void CreateServer() { // Try UPnP port mapping nonetheless if (!Network.HavePublicAddress() && !LocalMode) { MapPort(); } var result = Network.InitializeServer(2, Port, !Network.HavePublicAddress() && !LocalMode); if (result == NetworkConnectionError.NoError) { PeerType = NetworkPeerType.Server; if (!LocalMode) { MasterServer.RegisterHost("Diluvium", GameName, "1.1"); } waitingForClient = true; } else { PeerType = NetworkPeerType.Disconnected; errorMessage = "Couldn't create server (reason : " + result + ")"; Debug.Log(errorMessage); } }
void Update() { if (GameFlow.State == GameState.ReadyToConnect) { if (LocalMode) { PeerType = NetworkPeerType.Disconnected; IsClient = false; IsServer = true; CreateServer(); TerrainGrid.Instance.Summoners[TerrainGrid.ClientPlayerId].IsFakeAI = true; TerrainGrid.Instance.Summoners[TerrainGrid.ClientPlayerId].MarkReady(); GameFlow.State = GameState.ReadyToPlay; } else if (IsServer) { IsClient = false; CreateServer(); GameFlow.State = GameState.WaitingOrConnecting; } else { ConnectToServer(); IsClient = true; } } }
void Update() { peerType = Network.peerType; if (CheckPlayer) { if (noResponce) { player.SendMessage("Information", PlayerName); } if (!noResponce) { player.SendMessage("AllowMovement"); } } //This manages the server chat log. if (ServerLog.Count > 50) { ServerLog.RemoveAt(0); } if (!hasSpawned) { if (curState == ServerState.InGame && peerType == NetworkPeerType.Client) { SpawnPlayer(); } } //Debug.Log(hasSpawned + " : " + curState + " : " + peerType); }
public static bool CheckPeerType(NetworkPeerType peerType) { if (peerType == Network.peerType) { return(true); } return(false); }
void ProcessMove(string msg, NetworkMessageInfo info) { //刚从网络接收的数据的相关信息,会被保存到NetworkMessageInfo这个结构中 string sender = info.sender.ToString(); Debug.Log(sender); //看脚本运行在什么状态下 NetworkPeerType status = Network.peerType; if (status == NetworkPeerType.Server) { myself = cube01; //假如运行在server状态下, 那么自己就是cube1 } else { myself = cube01; //假如运行在client状态下, 那么自己就是cube2 } //假如是自己发送的信息 if (sender == "-1") { if (msg == "W") { myself.transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed); } if (msg == "S") { myself.transform.Translate(Vector3.back * Time.deltaTime * moveSpeed); } if (msg == "A") { myself.transform.Translate(Vector3.left * Time.deltaTime * moveSpeed); } if (msg == "D") { myself.transform.Translate(Vector3.right * Time.deltaTime * moveSpeed); } } //假如是别人发送的信息 else { if (msg == "W") { myself.transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed); } if (msg == "S") { myself.transform.Translate(Vector3.back * Time.deltaTime * moveSpeed); } if (msg == "A") { myself.transform.Translate(Vector3.left * Time.deltaTime * moveSpeed); } if (msg == "D") { myself.transform.Translate(Vector3.right * Time.deltaTime * moveSpeed); } } }
void Start() { Application.runInBackground = true; if (!GetComponent <NetworkView>()) { gameObject.AddComponent <NetworkView>(); } IMG = DefaultIMG; peerType = Network.peerType; inst = this; }
public void RPCReceiverMessageFromPeer(string msg, NetworkMessageInfo info) { //刚从网络接收的数据的相关信息,会被保存到NetworkMessageInfo这个结构中 string sender = info.sender.ToString(); //看脚本运行在什么状态下 NetworkPeerType status = Network.peerType; if (status != NetworkPeerType.Disconnected && sender != "-1") { receiverMessageFromPeer(msg); } }
void OnFailedToConnect(NetworkConnectionError error) { if (IsServer) { return; // Failed to connect to master server } PeerType = NetworkPeerType.Disconnected; errorMessage = "Couldn't connect to server (reason : " + error + ") -- will retry in 2 seconds..."; Debug.Log(errorMessage); TaskManager.Instance.WaitFor(2).Then(() => GameFlow.State = GameState.ReadyToConnect); }
/// <summary> /// Returns a string representing the type of the peer and network status that the peer is in. /// </summary> /// <param name="peerType"></param> /// <param name="status"></param> /// <returns></returns> public static string GetStatusString(NetworkPeerType peerType, NetworkStatus status) { switch (peerType) { case NetworkPeerType.Disconnected: return("Disconnected"); case NetworkPeerType.Server: switch (status) { case NetworkStatus.Disconnected: return("Server Disconnected"); case NetworkStatus.Connecting: return("Server Initializing"); case NetworkStatus.Connected: return("Server Initialized"); case NetworkStatus.Disconnecting: return("Server Shuttingdown"); } break; case NetworkPeerType.Client: switch (status) { case NetworkStatus.Disconnected: return("Client Disconnected"); case NetworkStatus.Connecting: return("Client Connecting"); case NetworkStatus.Connected: return("Client Connected"); case NetworkStatus.Disconnecting: return("Client Disconnecting"); } break; case NetworkPeerType.CellServer: switch (status) { case NetworkStatus.Disconnected: return("CellServer Disconnected"); case NetworkStatus.Connecting: return("CellServer Connecting"); case NetworkStatus.Connected: return("CellServer Connected"); case NetworkStatus.Disconnecting: return("CellServer Disconnecting"); } break; } return(peerType.ToString() + status); }
public override NetworkState GetConnectionState() { NetworkPeerType peerType = Network.peerType; if (peerType == NetworkPeerType.Client) { return(NetworkState.Client); } else if (peerType == NetworkPeerType.Server) { return(NetworkState.Server); } else { return(NetworkState.Disconnected); } }
void CreateServer() { // Try UPnP port mapping nonetheless if (!Network.HavePublicAddress() && !LocalMode) MapPort(); var result = Network.InitializeServer(2, Port, !Network.HavePublicAddress() && !LocalMode); if (result == NetworkConnectionError.NoError) { PeerType = NetworkPeerType.Server; if (!LocalMode) MasterServer.RegisterHost("Diluvium", GameName, "1.1"); waitingForClient = true; } else { PeerType = NetworkPeerType.Disconnected; errorMessage = "Couldn't create server (reason : " + result + ")"; Debug.Log(errorMessage); } }
internal void leaveWiFi() { type = NetworkPeerType.Unknown; isActive = false; }
void init() { type = NetworkPeerType.Unknown; isActive = false; isSetIP = storage.IPAddress != null; isSetHostName = storage.HostName != null; }
void ConnectToServer() { Debug.Log("connection attempt will start"); var isIp = (new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")).IsMatch(GameName); if (isIp) { var result = Network.Connect(GameName, Port); if (result == NetworkConnectionError.NoError) { PeerType = NetworkPeerType.Connecting; } else { PeerType = NetworkPeerType.Disconnected; errorMessage = "Couldn't connect to server (reason : " + result + ") -- will retry in 2 seconds..."; TaskManager.Instance.WaitFor(2).Then(() => GameFlow.State = GameState.ReadyToConnect); Debug.Log(errorMessage); } } else { MasterServer.RequestHostList("Diluvium"); HostData chosenHost = null; foreach (var host in MasterServer.PollHostList().OrderBy(a => Guid.NewGuid())) { Debug.Log("Server found : " + " | game name : " + host.gameName + ", version = " + host.comment); if ((host.gameName == GameName || GameName == string.Empty) && host.comment == Version) { Debug.Log("Found host"); chosenHost = host; break; } } if (chosenHost == null) { errorMessage = "Couldn't connect to server (reason : not present in master server) -- will retry in 2 seconds..."; TaskManager.Instance.WaitFor(2).Then(() => GameFlow.State = GameState.ReadyToConnect); Debug.Log(errorMessage); } else { chosenHost.useNat = true; var result = Network.Connect(chosenHost.guid); if (result == NetworkConnectionError.NoError) { PeerType = NetworkPeerType.Connecting; } else { PeerType = NetworkPeerType.Disconnected; errorMessage = "Couldn't connect to server (reason : " + result + ") -- will retry in 2 seconds..."; TaskManager.Instance.WaitFor(2).Then(() => GameFlow.State = GameState.ReadyToConnect); Debug.Log(errorMessage); } } } GameFlow.State = GameState.WaitingOrConnecting; }
void ConnectToServer() { Debug.Log("connection attempt will start"); var isIp = (new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")).IsMatch(GameName); if (isIp) { var result = Network.Connect(GameName, Port); if (result == NetworkConnectionError.NoError) PeerType = NetworkPeerType.Connecting; else { PeerType = NetworkPeerType.Disconnected; errorMessage = "Couldn't connect to server (reason : " + result + ") -- will retry in 2 seconds..."; TaskManager.Instance.WaitFor(2).Then(() => GameFlow.State = GameState.ReadyToConnect); Debug.Log(errorMessage); } } else { MasterServer.RequestHostList("Diluvium"); HostData chosenHost = null; foreach (var host in MasterServer.PollHostList().OrderBy(a => Guid.NewGuid())) { Debug.Log("Server found : " + " | game name : " + host.gameName + ", version = " + host.comment); if ((host.gameName == GameName || GameName == string.Empty) && host.comment == Version) { Debug.Log("Found host"); chosenHost = host; break; } } if (chosenHost == null) { errorMessage = "Couldn't connect to server (reason : not present in master server) -- will retry in 2 seconds..."; TaskManager.Instance.WaitFor(2).Then(() => GameFlow.State = GameState.ReadyToConnect); Debug.Log(errorMessage); } else { chosenHost.useNat = true; var result = Network.Connect(chosenHost.guid); if (result == NetworkConnectionError.NoError) PeerType = NetworkPeerType.Connecting; else { PeerType = NetworkPeerType.Disconnected; errorMessage = "Couldn't connect to server (reason : " + result + ") -- will retry in 2 seconds..."; TaskManager.Instance.WaitFor(2).Then(() => GameFlow.State = GameState.ReadyToConnect); Debug.Log(errorMessage); } } } GameFlow.State = GameState.WaitingOrConnecting; }
void OnFailedToConnect(NetworkConnectionError error) { if (IsServer) return; // Failed to connect to master server PeerType = NetworkPeerType.Disconnected; errorMessage = "Couldn't connect to server (reason : " + error + ") -- will retry in 2 seconds..."; Debug.Log(errorMessage); TaskManager.Instance.WaitFor(2).Then(() => GameFlow.State = GameState.ReadyToConnect); }
void Start() { Application.runInBackground = true; if(!GetComponent<NetworkView>()) { gameObject.AddComponent<NetworkView>(); } IMG = DefaultIMG; peerType = Network.peerType; inst = this; }
void OnDisconnectedFromServer(NetworkDisconnection info) { PeerType = NetworkPeerType.Disconnected; errorMessage = "Disconnected from server (reason : " + info + ")"; // TODO : prompt for reconnection? }
void OnConnectedToServer() { PeerType = NetworkPeerType.Client; GameFlow.State = GameState.ReadyToPlay; Debug.Log("Connection successful : game starting!"); }
void OnConnectedToServer() { PeerType = NetworkPeerType.Client; GameFlow.State = GameState.ReadyToPlay; Debug.Log("Connection successful : game starting!"); }
void OnDisconnectedFromServer(NetworkDisconnection info) { PeerType = NetworkPeerType.Disconnected; errorMessage = "Disconnected from server (reason : " + info + ")"; // TODO : prompt for reconnection? }
void Update() { peerType = Network.peerType; if(ServerLog.Count > 50) ServerLog.RemoveAt(0); if(!hasSpawned) { SpawnPlayer(); } }
void Update() { if (GameFlow.State == GameState.ReadyToConnect) { if (LocalMode) { PeerType = NetworkPeerType.Disconnected; IsClient = false; IsServer = true; CreateServer(); TerrainGrid.Instance.Summoners[TerrainGrid.ClientPlayerId].IsFakeAI = true; TerrainGrid.Instance.Summoners[TerrainGrid.ClientPlayerId].MarkReady(); GameFlow.State = GameState.ReadyToPlay; } else if (IsServer) { IsClient = false; CreateServer(); GameFlow.State = GameState.WaitingOrConnecting; } else { ConnectToServer(); IsClient = true; } } }
internal void updateWiFi(WiFiStation wiFiStation) { type = NetworkPeerType.WiFi; isActive = true; this.storage.MACAddress = wiFiStation.MacAddress; }
void Start() { Application.runInBackground = true; if(!GetComponent<NetworkView>()) { gameObject.AddComponent<NetworkView>(); } peerType = Network.peerType; }
void Update() { peerType = Network.peerType; if(CheckPlayer) { if(noResponce) { player.SendMessage("Information", PlayerName); } if(!noResponce) { player.SendMessage("AllowMovement"); } } //This manages the server chat log. if(ServerLog.Count > 50) ServerLog.RemoveAt(0); if(!hasSpawned) { if(curState == ServerState.InGame && peerType == NetworkPeerType.Client) { SpawnPlayer(); } } //Debug.Log(hasSpawned + " : " + curState + " : " + peerType); }