public override void ServerStart() { if (!Available()) { Debug.Log("Not connected to relay! Server failed to start."); return; } if (_isClient || _isServer) { Debug.Log("Cannot host while already hosting or connected!"); return; } _isServer = true; _connectedRelayClients = new BiDictionary <int, int>(); _currentMemberId = 1; int pos = 0; _clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.CreateRoom); _clientSendBuffer.WriteInt(ref pos, maxServerPlayers); _clientSendBuffer.WriteString(ref pos, serverName); _clientSendBuffer.WriteBool(ref pos, isPublicServer); _clientSendBuffer.WriteString(ref pos, extraServerData); clientToServerTransport.ClientSend(0, new ArraySegment <byte>(_clientSendBuffer, 0, pos)); }
public override void ServerStart() { if (!Available()) { Debug.Log("Not connected to relay! Server failed to start."); return; } if (_isClient || _isServer) { Debug.Log("Cannot host while already hosting or connected!"); return; } _isServer = true; _connectedRelayClients = new BiDictionary <int, int>(); _currentMemberId = 1; _connectedDirectClients = new BiDictionary <int, int>(); var keys = new List <IPEndPoint>(_serverProxies.GetAllKeys()); for (int i = 0; i < keys.Count; i++) { _serverProxies.GetByFirst(keys[i]).Dispose(); _serverProxies.Remove(keys[i]); } int pos = 0; _clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.CreateRoom); _clientSendBuffer.WriteInt(ref pos, maxServerPlayers); _clientSendBuffer.WriteString(ref pos, serverName); _clientSendBuffer.WriteBool(ref pos, isPublicServer); _clientSendBuffer.WriteString(ref pos, extraServerData); // If we have direct connect module, and our local IP isnt null, tell server. Only time local IP is null is on cellular networks, such as IOS and Android. _clientSendBuffer.WriteBool(ref pos, _directConnectModule != null ? GetLocalIp() != null ? true : false : false); if (_directConnectModule != null && GetLocalIp() != null) { _clientSendBuffer.WriteString(ref pos, GetLocalIp()); // Transport port will be NAT port + 1 for the proxy connections. _directConnectModule.StartServer(useNATPunch ? _NATIP.Port + 1 : -1); } else { _clientSendBuffer.WriteString(ref pos, "0.0.0.0"); } if (useNATPunch) { _clientSendBuffer.WriteBool(ref pos, true); _clientSendBuffer.WriteInt(ref pos, 0); } else { _clientSendBuffer.WriteBool(ref pos, false); _clientSendBuffer.WriteInt(ref pos, _directConnectModule == null ? 1 : _directConnectModule.SupportsNATPunch() ? _directConnectModule.GetTransportPort() : 1); } clientToServerTransport.ClientSend(0, new ArraySegment <byte>(_clientSendBuffer, 0, pos)); }