예제 #1
0
        private void __ProcessClientMessages(Gear obj)
        {
            UnityClients.ValueCollection clients = clientsUnity.Values;

            foreach (UnityClient unityClient in clients)
            {
                Client2 client = unityClient.client;

                unityClient.ProcessMessageQueue(unityClient.messageQueueIn, EClientMessageFlow.INCOMING);
            }

            foreach (UnityClient unityClient in clients)
            {
                Client2 client = unityClient.client;

                testServerSendPacket(client);

                //unityClient.ProcessMessageQueue(unityClient.messageQueueOut, EClientMessageFlow.OUTGOING);

                SendData(packetStreamTemp, client);
            }
        }
예제 #2
0
        private void __OnCheckClientsAlive(Gear obj)
        {
            int    debugIndentCounter = 0;
            double timeNow            = GetTimeSinceStart();

            UnityClients.ValueCollection clients = clientsUnity.Values;
            foreach (UnityClient unityClient in clients)
            {
                double diffNow        = timeNow - unityClient.timeLastReceived;
                double diffSeconds    = diffNow * 0.001f;
                double diffFromForget = timeForForget - diffSeconds;
                int    diffInt        = (int)(diffFromForget);
                int    restInt        = (int)(timeForForget - diffInt);

                string cliStr = unityClient.id.ToString();
                //Log.BufferString(unityClient.id + ": " + "#".Times(diffInt) + " ".Times(restInt) + " ".Times(3 - cliStr.Length));

                debugIndentCounter++;
                if ((debugIndentCounter % 4) == 0)
                {
                    Log.BufferString("\n");
                }

                if (!unityClient.HasStatus(EClientStatus.SLEEPING))
                {
                    if (diffSeconds > timeForSleep)
                    {
                        unityClient.status |= EClientStatus.SLEEPING;
                        if (OnStatusSleeping != null)
                        {
                            OnStatusSleeping(unityClient);
                        }
                    }
                }
                else if (!unityClient.HasStatus(EClientStatus.DISCONNECTED))
                {
                    if (diffSeconds > timeForForget)
                    {
                        unityClient.status |= EClientStatus.DISCONNECTED;
                        if (clientsToForget.Contains(unityClient))
                        {
                            throw new Exception("OnUnityCheckClientsAlive ERROR - clientsToForget already has this client: " + unityClient.ToString());
                        }
                        clientsToForget.Add(unityClient);
                    }
                }
            }

            //If there are any clients to forget, clear them out of the client-lists (Unity-based AND internal one):
            if (clientsToForget.Count > 0)
            {
                foreach (UnityClient unityClient in clientsToForget)
                {
                    clientsUnity.Remove(unityClient.client);
                    if (OnStatusDisconnected != null)
                    {
                        OnStatusDisconnected(unityClient);
                    }
                    ForgetClient(unityClient.client.endpointIn);
                }

                clientsToForget.Clear();
            }
        }