Esempio n. 1
0
 internal bool IsNewerThan(NetworkPacket networkPacket)
 {
     return(this.Timestamp > networkPacket.Timestamp);
 }
Esempio n. 2
0
 private static void ProcessPing(NetworkPacket packet)
 {
     PingPacket ping = packet as PingPacket;
 }
Esempio n. 3
0
 internal static void SendToHost(NetworkPacket packet)
 {
     NetworkInterface.SendPacket(NetworkInterface.HostEndPoint, packet);
 }
Esempio n. 4
0
 public Task SendPacketTo(StreamSocket destinationSocket, NetworkPacket packet)
 {
     byte[] message = CreateMessageFromPacket(packet);
     return(SendTo(destinationSocket, message));
 }
Esempio n. 5
0
 public Task SendPacketToAll(List <StreamSocket> destinationSockets, NetworkPacket packet)
 {
     byte[] message = CreateMessageFromPacket(packet);
     return(SendToAll(destinationSockets, message));
 }
Esempio n. 6
0
 public async Task EnterLobby(string playerID)
 {
     NetworkPacket replyPacket = await SendLobbyCommand(playerID, LobbyCommands.EnterLobby, _myAddress);
 }
Esempio n. 7
0
 public Task SendPacketToHost(NetworkPacket packet)
 {
     return(SendPacketTo(_hostSocket, packet));
 }
Esempio n. 8
0
 public static void SendPacket(IPEndPoint endpoint, NetworkPacket packet)
 {
     byte[] message = packet.CreateMessageFromPacket();
     SendDataToClient(endpoint, message);
 }
Esempio n. 9
0
 internal PacketReceivedEventArgs(StreamSocket source, NetworkPacket packet)
 {
     Packet = packet;
     Source = source;
 }
Esempio n. 10
0
 public async Task InitializeGame(string playerID)
 {
     NetworkPacket replyPacket = await SendLobbyCommand(playerID, LobbyCommands.SetupGame);
 }
Esempio n. 11
0
 private static void OnPacketReceived(IPEndPoint source, NetworkPacket packet)
 {
     PacketReceived?.Invoke(null, new PacketReceivedEventArgs(source, packet));
 }
Esempio n. 12
0
 public async Task LeaveGame(string playerID)
 {
     NetworkPacket replyPacket = await SendLobbyCommand(playerID, LobbyCommands.LeaveGame);
 }
Esempio n. 13
0
 public async Task JoinGame(string playerID, string hostID)
 {
     NetworkPacket replyPacket = await SendLobbyCommand(playerID, LobbyCommands.JoinGame, hostID);
 }
Esempio n. 14
0
 public async Task HostGame(string playerID)
 {
     NetworkPacket replyPacket = await SendLobbyCommand(playerID, LobbyCommands.HostGame, _myAddress);
 }
Esempio n. 15
0
 internal PacketReceivedEventArgs(IPEndPoint source, NetworkPacket packet)
 {
     Packet   = packet;
     SourceIP = source;
 }
Esempio n. 16
0
 private void OnPacketReceived(StreamSocket source, NetworkPacket packet)
 {
     PacketReceived?.Invoke(this, new PacketReceivedEventArgs(source, packet));
 }
Esempio n. 17
0
        internal async void OnPacketReceived(object network, PacketReceivedEventArgs args)
        {
            StreamSocket  source = args.Source;
            NetworkPacket packet = args.Packet;

            if (packet.Type == PacketType.LobbyCommand)
            {
                LobbyCommandPacket command  = packet as LobbyCommandPacket;
                string             playerID = command.PlayerID;

                if (Server)
                {
                    switch ((int)command.Command)
                    {
                    case (int)LobbyCommands.EnterLobby:
                        await ProcessEnterLobbyCommand(playerID, source.Information.RemoteAddress.DisplayName);

                        break;

                    case (int)LobbyCommands.LeaveLobby:
                        ProcessLeaveLobbyCommand(playerID);
                        break;

                    case (int)LobbyCommands.HostGame:
                        string hostIPAddress = command.Data;
                        ProcessHostGameCommand(playerID, hostIPAddress);
                        break;

                    case (int)LobbyCommands.JoinGame:
                        string hostID = command.Data;
                        ProcessJoinGameCommand(playerID, hostID);
                        break;

                    case (int)LobbyCommands.LeaveGame:
                        ProcessLeaveGameCommand(playerID);
                        break;

                    case (int)LobbyCommands.SetupGame:
                        await ProcessSetupGameCommand(playerID);

                        break;
                    }
                    await UpdateAllClients();

                    MenuManager.PlayerListChanged();
                }
                else
                {
                    switch ((int)command.Command)
                    {
                    case (int)LobbyCommands.EjectThisUser:
                        ProcessEjectThisUserCommand();
                        break;
                    }
                }
            }
            else if (packet.Type == PacketType.LobbyData && !Server)
            {
                LobbyData data = packet as LobbyData;
                _playerList = data._playerList;
                _gameList   = data._gameList;
                MenuManager.PlayerListChanged();
            }
        }
Esempio n. 18
0
 private Task SendUDPPacketToPlayer(PlayerData player, NetworkPacket packet)
 {
     return(_networkConnection.SendUDPData(player.IPAddress, player.Port, packet));
 }