Пример #1
0
 // TODO D: This is really sloppy way to move players (5s should be part of velocity of player)
 public void HandlePlayerMoving(string username, InputsPacket inPacket)
 {
     Entity player = PlayerEntities[username];
     Vector2 delta = Vector2.Zero;
     Inputs input = inPacket.inputs;
     delta += (input.Up) ? new Vector2(0, -5) : Vector2.Zero;
     delta += (input.Down) ? new Vector2(0, 5) : Vector2.Zero;
     delta += (input.Left) ? new Vector2(-5, 0) : Vector2.Zero;
     delta += (input.Right) ? new Vector2(5, 0) : Vector2.Zero;
     player.DoAction("ChangeDeltaPosition", new ChangePositionArgs(delta));
     player.DoAction("ChangeInputSequence", new ChangeInputSequenceArgs(inPacket.sequence));
 }
Пример #2
0
        private void HandlePacket(NetIncomingMessage msg)
        {
            PacketType type = (PacketType)msg.ReadByte();
            switch (type)
            {
                case PacketType.UsernameKeywordCombo:
                    UsernameKeywordComboPacket unkwPacket = new UsernameKeywordComboPacket();
                    unkwPacket.Unpack(msg);
                    if (gameManager.PlayerSaves.ContainsKey(unkwPacket.username))
                    {
                        LoginVerificationPacket packet = new LoginVerificationPacket();
                        packet.message = "You are already logged in.";
                        ServerConsoleMessage(unkwPacket.username + " login error: Already logged in.");
                        SendUnconnectedMessage(packet, msg.SenderEndpoint);
                        //server.Connections.Remove(server.GetConnection(msg.SenderEndpoint));  // try
                    }
                    else
                    {
                        PlayerSave save = FileGrabber.getPlayerSave(isLocalGame, unkwPacket.username, unkwPacket.keyword);
                        if (!unkwPacket.keyword.Equals(save.Keyword))
                        {
                            LoginVerificationPacket packet = new LoginVerificationPacket();
                            packet.message = "Keyword does not match.";
                            ServerConsoleMessage(unkwPacket.username + " login error: Bad keyword.");
                            SendUnconnectedMessage(packet, msg.SenderEndpoint);
                            //server.Connections.Remove(server.GetConnection(msg.SenderEndpoint));  // try
                        }
                        else
                        {
                            LoginVerificationPacket packet = new LoginVerificationPacket();
                            packet.message = "verified";
                            gameManager.PlayerSaves.Add(unkwPacket.username, save);
                            gameManager.createPlayerEntityFromSave(unkwPacket.username);
                            gameManager.RUIDUsernames.Add(unkwPacket.username, msg.SenderConnection.RemoteUniqueIdentifier);
                            SendUnconnectedMessage(packet, msg.SenderEndpoint);
                            ServerConsoleMessage(unkwPacket.username + " has logged into the game.");
                            if (!isLocalGame)
                            {
                                ChatMessageQueue.Enqueue(new ChatMessage("SERVER", unkwPacket.username + " has connected."));
                            }
                        }
                    }
                    break;

                case PacketType.ChatMessage:
                    ChatMessagePacket chatPacket = new ChatMessagePacket();
                    chatPacket.Unpack(msg);
                    string username = gameManager.RUIDUsernames.GetValue(msg.SenderConnection.RemoteUniqueIdentifier);
                    if (!username.Equals(""))
                    {
                        ChatMessage cmsg = new ChatMessage(username, chatPacket.message);
                        ChatMessageQueue.Enqueue(cmsg);
                        ServerConsoleMessage(cmsg.getChatString());
                    }
                    break;

                case PacketType.InputsPacket:
                    InputsPacket inputsPacket = new InputsPacket();
                    inputsPacket.Unpack(msg);
                    string un = gameManager.RUIDUsernames.GetValue(msg.SenderConnection.RemoteUniqueIdentifier);
                    if (!un.Equals(""))
                    {
                        gameManager.HandlePlayerMoving(un, inputsPacket);
                    }
                    break;
            }
        }
Пример #3
0
 public void HandleOutgoingMessages(Inputs inputs)
 {
     if (inputs.HasKeyDown())
     {
         InputsPacket inputPacket = new InputsPacket();
         inputPacket.inputs = inputs;
         inputPacket.sequence = ClientGameManager.Instance.Key;
         SendUnreliableData(inputPacket);
     }
 }