Beispiel #1
0
        public GameClient(TcpClient client)
        {
            netstream = client.GetStream();

            timer = new Stopwatch();

            byte[] message = new byte[4096];
            int    msgsize = 0;

            while (true)
            {
                timer.Start();
                try { msgsize = netstream.Read(message, 0, 4096); }
                catch { break; } //socket error

                if (msgsize == 0)
                {
                    break; //client disconnected
                }

                //message received
                HandlePacket(message.Take(msgsize).ToArray());
            }

            GameServer.PlayerCount--;
            GConsole.WriteStatus("User '{0}' disconnected.", this.UserID);

            client.Close();
        }
Beispiel #2
0
        public GameLSClient(TcpClient client)
        {
            GameServer.LoginServer = this;

            netstream = client.GetStream();

            byte[] message = new byte[4096];
            int    msgsize = 0;

            while (true)
            {
                try { msgsize = netstream.Read(message, 0, 4096); }
                catch { break; } //socket error

                if (msgsize == 0)
                {
                    break; // lost connection to login server
                }

                //message received
                HandlePacket(message.Take(msgsize).ToArray());
            }

            GConsole.WriteError("Lost connection to loginserver.");

            client.Close();
        }
Beispiel #3
0
        public void Connect(CGConnect packet)
        {
            this.UserID = GameServer.AuthPlayers[packet.AuthKey];
            GameServer.AuthPlayers.Remove(packet.AuthKey);
            this.PCName = packet.PCName;

            GConsole.WriteStatus("Received CGConnectPacket: {0}:{1}:{2}", this.UserID, this.PCName, packet.AuthKey);

            PCSlayerInfo2 pc     = DBManager.GetPCSlayerInfo2(packet.PCName);
            GCUpdateInfo  answer = new GCUpdateInfo(pc);

            answer.Write(ref netstream);
        }
Beispiel #4
0
        public static void Initialize(IPAddress ip, int port, IPAddress loginip, int loginport)
        {
            IPAddressGame  = ip;
            IPAddressLogin = loginip;
            PortLogin      = loginport;
            PortGame       = port;

            AuthPlayers = new Dictionary <int, string>();

            // Initialize DBManager
            DBManager.Initialize();

            // Initialize TCPListener
            tcpListener = new TcpListener(ip, port);

            // Connect to login server
            GConsole.WriteStatus("Connecting to LoginServer at {0}:{1}.", loginip, loginport);

            bool loop = true;

            while (loop)
            {
                try
                {
                    TcpClient tcpLSClient = new TcpClient(loginip.ToString(), loginport);
                    Thread    tLSListen   = new Thread(new ParameterizedThreadStart(HandleLSClient));
                    tLSListen.Start(tcpLSClient);

                    GConsole.WriteStatus("Connected to LoginServer.");

                    loop = false;
                }
                catch
                {
                    GConsole.WriteError("Failed connecting to LoginServer. Trying again in 5 seconds...");
                    Thread.Sleep(5000);
                }
            }

            // Listen for clients
            tListen = new Thread(new ThreadStart(ListenClients));
            tListen.Start();
        }
Beispiel #5
0
 public void Say(CGSay packet)
 {
     GConsole.WriteStatus("{0} says \"{1}\"", this.PCName, packet.Message);
 }
Beispiel #6
0
        public void IncomingConnection(LGIncomingConnection packet)
        {
            GameServer.AuthPlayers.Add(packet.AuthKey, packet.UserID);

            GConsole.WriteStatus("Received LGIncomingConnection: {0}:{1}:{2}", packet.UserID, packet.PCName, packet.AuthKey);
        }