private void ProcessJoinRequest(GameServer gameServer, JoinRequest msg, INetworkAddress address) { Debug.LogFormat("Join request from player {0}. Address {1}", msg.m_playerName, address.ToString()); if (gameServer.GetClientCount() == 2) { Debug.Log("Server is full."); return; } if (gameServer.IsClientConnected(address)) { Debug.Log("Client is already connected."); return; } gameServer.AddClient(new ClientInfo(msg.m_playerName, (byte)gameServer.GetClientCount(), address)); gameServer.AcceptClient(address); // if (gameServer.GetClientCount() == 2) { gameServer.SendOpponentFound(); gameServer.NotifyPlayersConnected(); } }
public ClientInfo(string name, byte team, INetworkAddress address) { Name = name; Team = team; Address = address; LastMsgNum = -1; }
public GeolocationService(IGeolocationRepository geolocationRepository, IIpDetailsService service, INetworkAddress networkAddress) { _geolocationRepository = geolocationRepository; _service = service; _networkAddress = networkAddress; }
public void AcceptClient(INetworkAddress address) { var joinAccept = new JoinAccept(); joinAccept.m_team = (byte)(GetClientCount() - 1); m_netMsgSerializer.Serialize(joinAccept); m_com.Send(m_netMsgSerializer.Data, m_netMsgSerializer.DataSize, address); }
public InstructionSenderTests() { _networkAddress = Mock.Create <INetworkAddress>(); _nodeVisitor = Mock.Create <INodeVisitor>(); _sessionHolder = Mock.Create <ISessionHolder>(); _recorder = Mock.Create <IRecorder>(); _sut = new InstructionSender(_nodeVisitor, _networkAddress, _sessionHolder, _recorder); }
private (bool, ISession) TryConnectInternal(INetworkAddress networkAddress) { if (_networkConnector.TryConnect(networkAddress, out INetworkTunnel tunnel)) { return(true, _sessionFactory.Invoke(tunnel)); } return(false, default);
public void Send(byte[] data, int size, INetworkAddress address) { var dataAndAddr = new DataAndAddress() { data = new RawData(data, size), address = address }; m_sendQueue.Enqueue(dataAndAddr); }
public void Send(byte[] data, int size, INetworkAddress address) { INetworkCommunication netCom; if (!m_addrToCom.TryGetValue(address, out netCom)) { netCom = m_defaultSendCom; } netCom.Send(data, size, address); }
public void Send(byte[] data, int size, INetworkAddress address) { var postMsg = new PostMsg(); postMsg.m_timeToSend = Time.time + m_delay; postMsg.m_data = new byte[size]; postMsg.m_address = address; System.Array.Copy(data, postMsg.m_data, size); m_postMsgQueue.Enqueue(postMsg); }
public NetworkPoint( INetworkAddress networkAddress, Func <ISocket, INetworkTunnel> networkTunnelFactory, Func <AddressFamily, SocketType, ProtocolType, ISocket> socketFactory, IRecorder recorder) { _recorder = recorder; _networkTunnelFactory = networkTunnelFactory; _sListener = socketFactory.Invoke(networkAddress.IP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Bind(networkAddress.IP, networkAddress.Port); Open(); }
public void AddNetworkCommunication(INetworkCommunication netCom, INetworkAddress address) { m_netComs.Add(netCom); if (address == null) { m_defaultSendCom = netCom; } else { m_addrToCom[address] = netCom; } }
private void ProcessReadyToStart(GameServer gameServer, ReadyToStart msg, INetworkAddress address) { Debug.LogFormat("ReadyToStart, Address: {0}", address.ToString()); var clientInfo = gameServer.GetClientInfoByAddress(address); if (clientInfo != null && clientInfo.IsReadyToStart) { return; } gameServer.SetReadyToStart(address); }
public FakeClient(UserInput input, string playerName, string netAddress) { m_userInput = input; OutMessages = new Queue <RawData>(); m_playerName = playerName; NetworkAddress = new FakeAddress(netAddress); if (m_userInput != null) { m_inputProc = new MatchInputProcessor(m_userInput); } }
public void Join() { var serverAddressGetter = new ServerAddressGetter(); m_serverAddress = serverAddressGetter.GetServerAddress(); var msg = new JoinRequest(); msg.m_clientVersion = 0; msg.m_playerName = SystemInfo.deviceName; m_netMsgSerializer.Serialize(msg); m_com.Send(m_netMsgSerializer.Data, m_netMsgSerializer.DataSize, m_serverAddress); }
public bool Receive(byte[] data, out int size, out INetworkAddress address) { var endPoint = new IPEndPoint(IPAddress.Any, 0); if (!m_socket.Receive(data, out size, ref endPoint)) { address = null; return(false); } address = new UdpNetworkAddress(endPoint); return(true); }
public ClientInfo GetClientInfoByAddress(INetworkAddress address) { if (ClientInfos[0] != null && ClientInfos[0].Address.Equals(address)) { return(ClientInfos[0]); } if (ClientInfos[1] != null && ClientInfos[1].Address.Equals(address)) { return(ClientInfos[1]); } return(null); }
public bool Receive(byte[] data, out int size, out INetworkAddress address) { if (m_recvQueue.Count > 0) { var dataAndAddr = m_recvQueue.Dequeue(); dataAndAddr.data.CopyTo(data, out size); address = dataAndAddr.address; return(true); } size = 0; address = null; return(false); }
public bool Receive(byte[] data, out int size, out INetworkAddress address) { foreach (var netCom in m_netComs) { if (netCom.Receive(data, out size, out address)) { return(true); } } size = 0; address = null; return(false); }
public bool Receive(byte[] data, out int size, out INetworkAddress address) { size = 0; address = null; if (OutMessages.Count == 0) { return(false); } address = m_serverAddress; var rawData = OutMessages.Dequeue(); rawData.CopyTo(data, out size); return(true); }
public void SetReadyToStart(INetworkAddress address) { var clientInfo = GetClientInfoByAddress(address); if (clientInfo == null) { return; } clientInfo.IsReadyToStart = true; if (ClientsReady()) { m_state = GameServerMatchState.Get(); } }
public bool Receive(byte[] data, out int size, out INetworkAddress address) { size = 0; address = null; if (ReceiveFromClient(m_client1, data, ref size, ref address)) { return(true); } if (ReceiveFromClient(m_client2, data, ref size, ref address)) { return(true); } return(false); }
public bool TryConnect(INetworkAddress networkAddress, out INetworkTunnel networkTunnel) { bool result = false; networkTunnel = default; try { result = TryConnectInternal(networkAddress, out networkTunnel); } catch (Exception exception) { ExceptionHandler(exception); } return(result); }
public void ProcessMessage(GameServer gameServer, NetworkMessage netMsg, INetworkAddress address) { if (netMsg.m_type != NetworkMessageType.JoinRequest && !gameServer.IsClientConnected(address)) { Debug.LogFormat("Received the message {0} from not connected client {1}", netMsg.m_type, address.ToString()); return; } switch (netMsg.m_type) { case NetworkMessageType.JoinRequest: ProcessJoinRequest(gameServer, netMsg.m_msg as JoinRequest, address); break; case NetworkMessageType.ReadyToStart: ProcessReadyToStart(gameServer, netMsg.m_msg as ReadyToStart, address); break; } }
public void ProcessMessage(GameServer gameServer, NetworkMessage netMsg, INetworkAddress address) { if (!gameServer.IsClientConnected(address)) { Debug.LogFormat("Received the message {0} from not connected client {1}", netMsg.m_type, address.ToString()); return; } var clientInfo = gameServer.GetClientInfoByAddress(address); switch (netMsg.m_type) { case NetworkMessageType.PlayerMove: { var playerMove = netMsg.m_msg as PlayerMove; playerMove.m_team = clientInfo.Team; MatchMessage matchMsg = new MatchMessage(); matchMsg.m_message = playerMove; matchMsg.m_messageType = MessageType.PlayerMove; gameServer.AddMatchMessage(matchMsg); // Not sure it it supposed to be here. clientInfo.LastMsgNum = Mathf.Max(clientInfo.LastMsgNum, playerMove.m_messageNumber); break; } case NetworkMessageType.PlayerAction: { var msg = netMsg.m_msg as Action; msg.m_team = clientInfo.Team; MatchMessage matchMsg = new MatchMessage(); matchMsg.m_message = msg; matchMsg.m_messageType = MessageType.PlayerAction; gameServer.AddMatchMessage(matchMsg); // Not sure it it supposed to be here. clientInfo.LastMsgNum = Mathf.Max(clientInfo.LastMsgNum, msg.m_messageNumber); break; } } }
public void Connect(INetworkAddress hostAddress) { if (SamStream != null) { throw new InvalidOperationException("The host is already connected."); } else if (hostAddress == null) { throw new ArgumentNullException(nameof(hostAddress)); } else if (string.IsNullOrEmpty(hostAddress.Host) || hostAddress.Port == 0) { throw new ArgumentException($"Invalid host configuration. {nameof(hostAddress.Host)} must be set to valid DNS name or IP address.\nThe ${nameof(hostAddress.Port)} must be set."); } else { NetworkAddress = hostAddress; } Reconnect(); }
public void Send(byte[] data, int size, INetworkAddress address) { var netMsg = m_netMsgSerializer.Deserialize(data, size); if (netMsg == null) { return; } Debug.LogFormat("FakeServerNetworkCommunication: Send, size = {0}, type = {1}", size, netMsg.m_type); switch (netMsg.m_type) { case NetworkMessageType.JoinRequest: var msg = new JoinAccept(); msg.m_team = 0; m_netMsgSerializer.Serialize(msg); OutMessages.Enqueue(new RawData(m_netMsgSerializer.Data, m_netMsgSerializer.DataSize)); // TODO: add this message to OutMessages break; } }
private bool TryConnectInternal(INetworkAddress networkAddress, out INetworkTunnel networkTunnel) { var socket = _socketFactory.Invoke(networkAddress.IP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); var isFail = false; networkTunnel = default; SafeExecution.TryCatch( () => socket.Connect(networkAddress.IP, networkAddress.Port), e => { SafeExecution.TryCatch(() => socket.Dispose(), e => ExceptionHandler(e)); isFail = true; }); if (!isFail) { networkTunnel = _networkTunnelFactory.Invoke(socket); } return(!isFail); }
public (bool, ISession) TryConnect(INetworkAddress networkAddress) { return(SafeExecution.TryCatchWithResult(() => TryConnectInternal(networkAddress), ExceptionHandler)); }
public void Attach(INetworkAddress address) { DataStream.Connect(address); }
public bool IsClientConnected(INetworkAddress address) { return ((ClientInfos[0] != null && ClientInfos[0].Address.Equals(address)) || (ClientInfos[1] != null && ClientInfos[1].Address.Equals(address))); }