コード例 #1
0
 internal static void ReadFirstAskForServers(byte client, Packet _)
 {
     //Send existing servers saved on server to client
     foreach (Server server in InternetDiscoveryTCPServer.ServersAvailable)
     {
         InternetDiscoveryTCPServerSend.SendServerData(client, server);
     }
     InternetDiscoveryTCPServer.ClientDictionary[client].ServersAlreadyGiven = new List <Server>(InternetDiscoveryTCPServer.ServersAvailable);
     Output.WriteLine($"Read FirstAskForServers from client:{client}");
 }
コード例 #2
0
        internal static void ReadAskForServerChanges(byte client, Packet packet)
        {
            try
            {
                List <Server> serversGiven     = InternetDiscoveryTCPServer.ClientDictionary[client].ServersAlreadyGiven;
                List <Server> serversAvailable = InternetDiscoveryTCPServer.ServersAvailable;

                if (serversGiven.Count > serversAvailable.Count) //Must mean 1 or more servers deleted
                {
                    foreach (Server serverGiven in serversGiven)
                    {
                        bool givenServerFound = false;
                        foreach (Server serverAvailable in serversAvailable)
                        {
                            if (serverGiven == serverAvailable)
                            {
                                givenServerFound = true;
                                break;
                            }
                        }
                        if (!givenServerFound)
                        {
                            InternetDiscoveryTCPServerSend.SendServerDeleted(client, serverGiven);
                        }
                    }
                }

                foreach (Server serverAvailable in serversAvailable)
                {
                    bool foundServerMatch = false;
                    bool timeStampsMatch  = false;

                    foreach (Server serverGiven in serversGiven)
                    {
                        if (serverAvailable == serverGiven)
                        {
                            foundServerMatch = true;
                            if (serverAvailable.TimeStamp == serverGiven.TimeStamp)
                            {
                                timeStampsMatch = true;
                            }
                            break;
                        }
                    }

                    if (foundServerMatch && !timeStampsMatch)
                    {
                        InternetDiscoveryTCPServerSend.SendModifedServer(client, serverAvailable);
                    }
                    else if (!foundServerMatch)
                    {
                        InternetDiscoveryTCPServerSend.SendServerData(client, serverAvailable);
                    }
                }

                InternetDiscoveryTCPServer.ClientDictionary[client].ServersAlreadyGiven = new List <Server>(serversAvailable);
                Output.WriteLine($"Read AskForServerChanges from client:{client}");
            }
            catch (Exception exception)
            {
                Output.WriteLine($"Error ReadAskForServerChanges from client: {client}...\n{exception}");
            }
        }