Beispiel #1
0
        private static void Connection(IAsyncResult result)
        {
            try
            {
                _client.EndConnect(result);

                if (!_client.Connected)
                {
                    Connect();
                    return;
                }

                _receiveList = new ConcurrentQueue <Packet>();
                _sendList    = new ConcurrentQueue <Packet>();
                _retryList   = new ConcurrentQueue <Packet>();
                _rawData     = new byte[0];
                BeginReceive();
            }
            catch (SocketException)
            {
                Connect();
            }
            catch (Exception ex)
            {
                ServerManagerForm.SaveError(ex.ToString());
                Disconnect();
            }
        }
        public ServerManagerForm()
        {
            InitializeComponent();

            SMForm = this;

            usernameBox.Text  = Network.Username;
            passwordBox.Text  = Network.Password;
            ipBox.Text        = Network.ServerIP;
            portBox.Text      = Network.ServerPort.ToString();
            Application.Idle += Application_Idle;
            FormClosing      += ServerManagerForm_FormClosing;
            int dist = playerCountLbl.Location.Y - serverStatus.Location.Y;

            playerCountLbl.Location = new Point(serverStatus.Location.X, serverStatus.Location.Y + dist);
            mobCountLbl.Location    = new Point(serverStatus.Location.X, playerCountLbl.Location.Y + dist);
            Location          = new Point(serverStatus.Location.X, mobCountLbl.Location.Y + dist);
            cycleLbl.Location = new Point(serverStatus.Location.X, uptimeLbl.Location.Y + dist);
        }
Beispiel #3
0
        public static void Process()
        {
            if (_client == null || !_client.Connected)
            {
                if (Connected)
                {
                    while (_receiveList != null && !_receiveList.IsEmpty)
                    {
                        if (!_receiveList.TryDequeue(out Packet p) || p == null)
                        {
                            continue;
                        }
                        if (!(p is ServerPackets.Disconnect) && !(p is ServerPackets.ClientVersion))
                        {
                            continue;
                        }

                        ServerManagerForm.ProcessPacket(p);
                        _receiveList = null;
                        if (ServerManagerForm.SMForm.DebugLogs)
                        {
                            ServerManagerForm.SMForm.OutputNLogs(string.Format("[Network][FATAL][0]Connection Died\r\n"));
                        }
                        return;
                    }
                    if (ServerManagerForm.SMForm.DebugLogs)
                    {
                        ServerManagerForm.SMForm.OutputNLogs(string.Format("[Network][FATAL][1]Connection Died\r\n"));
                    }
                    Disconnect();
                    return;
                }
                return;
            }
            if (ServerManagerForm.Time > nextProcessConsole)
            {
                nextProcessConsole = ServerManagerForm.Time + 1500;
                if (ServerManagerForm.SMForm.DebugLogs)
                {
                    ServerManagerForm.SMForm.OutputNLogs(string.Format("[Network]Processing\r\n"));
                }

                Enqueue(new C.KeepAlive {
                    Time = ServerManagerForm.Time
                });
            }


            while (_receiveList != null && !_receiveList.IsEmpty)
            {
                if (!_receiveList.TryDequeue(out Packet p) || p == null)
                {
                    continue;
                }
                if (ServerManagerForm.SMForm.DebugLogs)
                {
                    ServerManagerForm.SMForm.OutputNLogs(string.Format("[Network][IN]Processing Packets..\r\n"));
                }
                ServerManagerForm.ProcessPacket(p);
            }
            while (_retryList.Count > 0)
            {
                if (!_retryList.TryDequeue(out Packet p) || p == null)
                {
                    continue;
                }
                _receiveList.Enqueue(p);
            }
            if (_sendList == null || _sendList.IsEmpty)
            {
                return;
            }

            List <byte> data = new List <byte>();

            while (!_sendList.IsEmpty)
            {
                if (!_sendList.TryDequeue(out Packet p))
                {
                    continue;
                }
                if (ServerManagerForm.SMForm.DebugLogs)
                {
                    ServerManagerForm.SMForm.OutputNLogs(string.Format("[Network][OUT]Processing Packets..\r\n"));
                }
                data.AddRange(p.GetPacketBytes());
            }
            BeginSend(data);
        }