Пример #1
0
        //masterserver sends connection count to balanceserver
        void Packet21(NetIncomingMessage inmsg, Masterserver ms)
        {
            int totalConnections;

            try { totalConnections = inmsg.ReadInt32(); }
            catch { return; }

            ms.timeout          = 0;
            ms.totalConnections = totalConnections;
        }
Пример #2
0
        //masterserver informs, if its enabled for hosting
        void Packet1(NetIncomingMessage inmsg, Masterserver ms)
        {
            bool isEnabled;

            try { isEnabled = inmsg.ReadBoolean(); }
            catch { return; }

            ms.enabled = isEnabled;

            /*if (!ms.enabled)
             * {
             *  lock (masterServers)
             *      masterServers.RemoveAll(p => ms.netConnection == inmsg.SenderConnection);
             * }*/
            AddText("masterserver enabled: " + isEnabled);
        }
Пример #3
0
        void Handler()
        {
            NetIncomingMessage inmsg;
            byte         b;
            Masterserver ms = null;

            while (true)
            {
                while ((inmsg = server.ReadMessage()) != null)
                {
                    switch (inmsg.MessageType)
                    {
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.ErrorMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.VerboseDebugMessage:
                        //Console.WriteLine(inmsg.ReadString());
                        break;

                    //*************************************************************************

                    case NetIncomingMessageType.ConnectionApproval:
                        inmsg.SenderConnection.Approve();

                        lock (masterServers)
                        {
                            masterServers.Add(new Masterserver(inmsg.SenderConnection));
                        }

                        break;

                    //*************************************************************************

                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)inmsg.ReadByte();

                        if (status == NetConnectionStatus.Disconnected)
                        {
                            lock (masterServers)
                                masterServers.RemoveAll(p => p.netConnection == inmsg.SenderConnection);
                        }

                        break;

                    //*************************************************************************

                    case NetIncomingMessageType.Data:
                        ms = masterServers.Find(p => p.netConnection == inmsg.SenderConnection);
                        if (ms == null || inmsg.LengthBytes < 1)
                        {
                            break;
                        }

                        b = inmsg.ReadByte();

                        //masterserver informs, if its enabled for hosting
                        if (b == 1)
                        {
                            Packet1(inmsg, ms);
                        }

                        //ms requests version
                        if (b == 2)
                        {
                            Packet2(inmsg);
                        }

                        //masterserver sends connection count to balanceserver
                        if (b == 21)
                        {
                            Packet21(inmsg, ms);
                        }

                        //timeout message
                        if (b == 84)
                        {
                            Packet84(inmsg, ms);
                        }

                        break;

                    //*************************************************************************

                    default:
                        Console.WriteLine("Unhandled type: " + inmsg.MessageType + " " + inmsg.LengthBytes + " bytes " + inmsg.DeliveryMethod + "|" + inmsg.SequenceChannel);
                        break;
                    }
                    server.Recycle(inmsg);
                }

                Thread.Sleep(1);
            }
        }
Пример #4
0
 //timeout message
 void Packet84(NetIncomingMessage inmsg, Masterserver ms)
 {
     ms.timeout = 0;
 }