Beispiel #1
0
 public static void Broadcast_UDP(NetworkPacket np, PlayerNetworkCommunication RequestProcessor)
 {
     if (Clients_List != null)
     {
         foreach (PlayerNetworkCommunication rp in Clients_List.Values)
         {
             if (RequestProcessor != rp && rp != null)
             {
                 rp.Send_unreliable_Message(np);
             }
         }
     }
 }
Beispiel #2
0
        private void Begin_Accept_Tcp_Client_Callback(IAsyncResult ar)
        {
            // End the operation and display the received data on
            // the console.


            TcpClient client = Tcp_Server.EndAcceptTcpClient(ar);

            Console.WriteLine("New Client Connected" + client.Client.RemoteEndPoint.ToString());

            IPEndPoint DistanceCLientAddress = (IPEndPoint)client.Client.RemoteEndPoint;



            // IEnumerable<PlayerNetworkCommunication> query = Clients_List.Where(RequestProcessor => RequestProcessor.DistanceCLientAddress == DistanceCLientAddress);


            //  if (query.Count() == 0)
            //  {
            // Prepare new player to join him to Game Server
            PlayerNetworkCommunication rp = new PlayerNetworkCommunication();

            rp.instance      = this;
            rp.CLientAddress = DistanceCLientAddress;
            rp.client        = client;
            bool Serverisfull = true;

            for (int i = 0; i < MaximumPlayersCount; i++)
            {
                if (Clients_List[i] == null)
                {
                    rp.PlayerIdentifier = i;

                    Serverisfull    = false;
                    Clients_List[i] = rp;
                    rp.Tcp_Proccess();
                    break;
                }
            }
            if (Serverisfull)
            {
                rp.Disconnect();
            }


            // Process the connection here. (Add the client to a
            // server table, read data, etc.)

            Tcp_Server.BeginAcceptTcpClient(Begin_Accept_Tcp_Client_Callback, Tcp_Server);
        }