Beispiel #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();
        }
Beispiel #2
0
 /// <summary>
 /// Sends the protocol data for adding itself to the ground.
 /// </summary>
 /// <param name="proto">A reference to the protocol.</param>
 /// <param name="player">The player for whom to add this to.</param>
 /// <param name="stackPos">The stack position of this thing.</param>
 public override void AddThisToGround(ProtocolSend proto, 
     Player player, Position pos, byte stackPos)
 {
     proto.AddItem(pos, this, stackPos);
 }
Beispiel #3
0
 /// <summary>
 /// Sends the protocol data for adding itself to the ground.
 /// </summary>
 /// <param name="proto">A reference to the protocol.</param>
 /// <param name="player">The player for whom to add this to.</param>
 /// <param name="stackPos">The stack position of this thing.</param>
 public override void AddThisToGround(ProtocolSend proto,
     Player Player, Position pos, byte stackPos)
 {
     proto.AddScreenCreature(this, Player.KnowsCreature(this),
         pos, stackPos);
 }
Beispiel #4
0
 /// <summary>
 /// Adds itself to the specified protocol.
 /// </summary>
 /// <remarks>This add is only called for map tiles and therefore,
 /// it only needs to know how to add itself to maptiles.</remarks>
 /// <param name="proto">The protocol to add itself to.</param>
 /// <param name="player">The player for whom to add.</param>
 public override void AddItself(ProtocolSend proto, Player player)
 {
     proto.AddGroundItem(this);
 }
Beispiel #5
0
 /// <summary>
 /// Adds itself to the protocol specified via the parameters.
 /// Only to be used when sending map tiles.
 /// </summary>
 /// <param name="proto">The protocol to add to.</param>
 /// <param name="player">The player for whom the add is being done.</param>
 public override void AddItself(ProtocolSend proto, Player player)
 {
     bool knowsCreature = player.KnowsCreature(this);
     proto.AddTileCreature(this, knowsCreature);
 }