Beispiel #1
0
        void RpcRelayData(MessageData receivedData)
        {
            if (!isLocalPlayer)
            {
                return;
            }

            //Console.WriteLine("Client Received data {0} {1}", receivedData.messages, receivedData.timestamp);

            receivedMessages += 1;
            totalDeltaTime   += stopwatch.ElapsedMilliseconds - receivedData.timestamp;

            TimeSpan ts        = stopwatch.Elapsed;
            string   timeStamp = string.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);

            if (MissingMessages.Remove(receivedData))
            {
                // This is a missing message that has shown up out-of-order

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine("Missing Msg: {0} {1} {2} {3}", timeStamp, receivedData.messages, receivedData.timestamp);
                Console.ResetColor();

                CmdLostMsg(receivedData);

                outOfOrderMessages += 1;
            }
            else if (!SentMessages.Contains(receivedData))
            {
                // This can be true if server double-sends SyncVar or if messages are not ack'ed and resent from server

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine("Unknown Msg: {0} {1} {2}", timeStamp, receivedData.messages, receivedData.timestamp);
                Console.ResetColor();

                unknownMessages += 1;
            }
            else
            {
                int msgIndex = SentMessages.IndexOf(receivedData);

                if (msgIndex > 0)
                {
                    // This should only be possible with unordered channels in some transports

                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("Out-of-order Msg: {0} {1} {2} {3}", timeStamp, msgIndex, receivedData.messages, receivedData.timestamp);
                    Console.ResetColor();

                    // copy earlier messages to MissingMessages list
                    for (int index = 0; index < msgIndex; index++)
                    {
                        MissingMessages.Add(SentMessages[0]);
                        CmdLostMsg(SentMessages[0]);
                    }

                    // remove up to, but not including, this message
                    // may result in unknownMessages later if these eventually show up
                    SentMessages.RemoveRange(0, msgIndex);
                }
            }

            // Remove the message from the backlog
            SentMessages.Remove(receivedData);
        }
Beispiel #2
0
        void Update()
        {
            if (!NetworkClient.active || !isLocalPlayer || shuttingDown)
            {
                return;
            }

            if (SentMessages.Count >= backlogLimit)
            {
                shuttingDown = true;

                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Excessive message backlog detected ({0}) -- Shutting down", SentMessages.Count);
                Console.ResetColor();

                connectionToServer.Disconnect();
                return;
            }

            if (stopwatch.ElapsedMilliseconds > lastCmdSyncData + sendInterval)
            {
                lastCmdSyncData = stopwatch.ElapsedMilliseconds;
                sentMessages   += 1;

                MessageData clientData = new MessageData();
                clientData.messages  = sentMessages;
                clientData.timestamp = lastCmdSyncData;

                // Add msg to backlog...SyncVar hook will remove it
                SentMessages.Add(clientData);

                //Console.WriteLine("Client Sending data {0} {1}", sentMessages, lastCmdSyncData);

                CmdSendData(clientData);
            }

            if (stopwatch.ElapsedMilliseconds > lastUpdateStats + (updateInterval * 1000))
            {
                lastUpdateStats = stopwatch.ElapsedMilliseconds;

                ClientStats stats;
                stats.sentMessages       = sentMessages;
                stats.receivedMessages   = receivedMessages;
                stats.pendingMessages    = SentMessages.Count;
                stats.missingMessages    = MissingMessages.Count;
                stats.unknownMessages    = unknownMessages;
                stats.outOfOrderMessages = outOfOrderMessages;
                stats.totalDeltaTime     = totalDeltaTime;

                //Console.WriteLine("Client Sending stats {0} {1} {2} {3} {4} {5} {6}",
                //    stats.sentMessages,
                //    stats.receivedMessages,
                //    stats.pendingMessages,
                //    stats.missingMessages,
                //    stats.unknownMessages,
                //    stats.outOfOrderMessages,
                //    stats.totalDeltaTime);

                CmdUpdateStats(stats);
            }
        }
Beispiel #3
0
 void CmdSendData(MessageData clientData)
 {
     //Console.WriteLine("Server Received data {0} {1}", clientData.messages, clientData.timestamp);
     msgRingBuffer[clientData.messages % 50] = clientData;
     RpcRelayData(clientData);
 }