Пример #1
0
        private void HandlePlayerConnection(Socket socket, ProtocolReceive protocolReceive, ProtocolSend protocolSend)
        {
            LoginInfo playerLogin = protocolReceive.HandlePlayerLogin(socket);
            GameWorld localWorld  = world;

#if DEBUG
            // TODO: Write message here ("Logging in (name/password-hash)...")
#endif
            // TODO: Kick current player and let this one log in
            if (localWorld.IsPlayerOnline(playerLogin.GetUsername()))
            {
                protocolSend.Reset();
                protocolSend.AddSorryBox("A player with this name is already online.");
                protocolSend.MarkSocketAsClosed();
                protocolSend.WriteToSocket();
#if DEBUG
                // TODO: Write message here ("Player is already online")
#endif
                return;
            }

            Player player = new Player(protocolSend);

            if (!player.LoadPlayer(playerLogin))
            {
                protocolSend.Reset();
                protocolSend.AddSorryBox("A player with this name is already online.");
                protocolSend.MarkSocketAsClosed();
                protocolSend.WriteToSocket();
#if DEBUG
                // TODO: Write message here ("Invalid username or password.")
#endif
                return;
            }

            localWorld.SendAddPlayer(player, player.CurrentPosition);
            protocolReceive.StartReceiving(world, player);
#if DEBUG
            // TODO: Write message here ("Logged in (name)")
#endif
            // TODO?: Threading
            //new PlayerThread(player, localWorld, protoReceive).StartThread();
        }
Пример #2
0
        private void HandlePlayerConnection(Socket socket, ProtocolReceive protocolReceive, ProtocolSend protocolSend)
        {
            LoginInfo playerLogin = protocolReceive.HandlePlayerLogin(socket);
            GameWorld localWorld = world;
            #if DEBUG
            // TODO: Write message here ("Logging in (name/password-hash)...")
            #endif
            // TODO: Kick current player and let this one log in
            if (localWorld.IsPlayerOnline(playerLogin.GetUsername()))
            {
                protocolSend.Reset();
                protocolSend.AddSorryBox("A player with this name is already online.");
                protocolSend.MarkSocketAsClosed();
                protocolSend.WriteToSocket();
            #if DEBUG
                // TODO: Write message here ("Player is already online")
            #endif
                return;
            }

            Player player = new Player(protocolSend);

            if (!player.LoadPlayer(playerLogin))
            {
                protocolSend.Reset();
                protocolSend.AddSorryBox("A player with this name is already online.");
                protocolSend.MarkSocketAsClosed();
                protocolSend.WriteToSocket();
            #if DEBUG
                // TODO: Write message here ("Invalid username or password.")
            #endif
                return;
            }

            localWorld.SendAddPlayer(player, player.CurrentPosition);
            protocolReceive.StartReceiving(world, player);
            #if DEBUG
            // TODO: Write message here ("Logged in (name)")
            #endif
            // TODO?: Threading
            //new PlayerThread(player, localWorld, protoReceive).StartThread();
        }