Added terminal commands for networking and fixed ui stuff
This commit is contained in:
parent
593f1ca9f8
commit
117f2ddfff
@ -607,9 +607,9 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
IPField: {fileID: 1974014777}
|
IPField: {fileID: 1974014777}
|
||||||
ClientPortField: {fileID: 0}
|
ClientPortField: {fileID: 2124238381}
|
||||||
ServerPortField: {fileID: 0}
|
ServerPortField: {fileID: 1813464171}
|
||||||
WorldRoot: {fileID: 0}
|
WorldRoot: {fileID: 605817613}
|
||||||
--- !u!114 &564042476
|
--- !u!114 &564042476
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -40,19 +40,23 @@ public class Client : MonoBehaviour {
|
|||||||
NetClient.Connect(ip, port);
|
NetClient.Connect(ip, port);
|
||||||
|
|
||||||
Debug.Log("Client launched!");
|
Debug.Log("Client launched!");
|
||||||
|
Term.Println("Client launched!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnConnected(NetworkMessage msg) {
|
public void OnConnected(NetworkMessage msg) {
|
||||||
Debug.Log("Connected!");
|
Debug.Log("Connected!");
|
||||||
|
Term.Println("Connected!");
|
||||||
NetClient.Send(PktType.TestMessage, new TextMessage("Hai, I connected!"));
|
NetClient.Send(PktType.TestMessage, new TextMessage("Hai, I connected!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDisconnected(NetworkMessage msg) {
|
public void OnDisconnected(NetworkMessage msg) {
|
||||||
Debug.Log("Disconnected!");
|
Debug.Log("Disconnected!");
|
||||||
|
Term.Println("Disconnected!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnError(NetworkMessage msg) {
|
public void OnError(NetworkMessage msg) {
|
||||||
Debug.LogError("Encountered a network error. Shutting down.");
|
Debug.LogError("Encountered a network error. Shutting down.");
|
||||||
|
Term.Println("Encountered a network error. Shutting down.");
|
||||||
NetClient.Disconnect();
|
NetClient.Disconnect();
|
||||||
Running = false;
|
Running = false;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,29 @@ public class NetworkEstablisher : MonoBehaviour {
|
|||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start () {
|
||||||
|
Term.AddCommand("join", "joins a server at localhost:3935", (args) => {
|
||||||
|
StartClient("localhost", 3935);
|
||||||
|
});
|
||||||
|
Term.AddCommand("join (ip)", "joins a server at given ip and port 3935", (args) => {
|
||||||
|
string ip = args[0];
|
||||||
|
StartClient(ip, 3935);
|
||||||
|
});
|
||||||
|
Term.AddCommand("join (ip) (port)", "joins a server at given ip and port", (args) => {
|
||||||
|
string ip = args[0];
|
||||||
|
int port = 3935;
|
||||||
|
int.TryParse(args[1], out port);
|
||||||
|
StartClient(ip, port);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
Term.AddCommand("host", "host a server at port 3935", (args) => {
|
||||||
|
StartServer(3935);
|
||||||
|
});
|
||||||
|
Term.AddCommand("host (port)", "host a server at given port", (args) => {
|
||||||
|
int port = 3935;
|
||||||
|
int.TryParse(args[0], out port);
|
||||||
|
StartServer(port);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update () {
|
void Update () {
|
||||||
|
@ -30,6 +30,7 @@ public class Server : MonoBehaviour {
|
|||||||
NetworkServer.RegisterHandler(MsgType.Error, OnError);
|
NetworkServer.RegisterHandler(MsgType.Error, OnError);
|
||||||
|
|
||||||
Debug.Log("Server started on port " + port);
|
Debug.Log("Server started on port " + port);
|
||||||
|
Term.Println("Server started on port " + port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandlePacket(NetworkMessage msg) {
|
public void HandlePacket(NetworkMessage msg) {
|
||||||
@ -39,9 +40,11 @@ public class Server : MonoBehaviour {
|
|||||||
TextMessage TextMsg = new TextMessage();
|
TextMessage TextMsg = new TextMessage();
|
||||||
TextMsg.Deserialize(msg.reader);
|
TextMsg.Deserialize(msg.reader);
|
||||||
Debug.Log("Received message: " + TextMsg.Message);
|
Debug.Log("Received message: " + TextMsg.Message);
|
||||||
|
Term.Println("Received message: " + TextMsg.Message);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Debug.LogError("Received an unknown packet, id: " + msg.msgType);
|
Debug.LogError("Received an unknown packet, id: " + msg.msgType);
|
||||||
|
Term.Println("Received an unknown packet, id: " + msg.msgType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,13 +52,16 @@ public class Server : MonoBehaviour {
|
|||||||
|
|
||||||
public void OnConnected(NetworkMessage msg) {
|
public void OnConnected(NetworkMessage msg) {
|
||||||
Debug.Log("Someone connected!");
|
Debug.Log("Someone connected!");
|
||||||
|
Term.Println("Someone connected!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDisconnected(NetworkMessage msg) {
|
public void OnDisconnected(NetworkMessage msg) {
|
||||||
Debug.Log("Someone disconnected?");
|
Debug.Log("Someone disconnected.");
|
||||||
|
Term.Println("Someone disconnected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnError(NetworkMessage msg) {
|
public void OnError(NetworkMessage msg) {
|
||||||
Debug.LogError("Encountered a network error on server");
|
Debug.LogError("Encountered a network error on server");
|
||||||
|
Term.Println("Encountered a network error on server");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user