private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            switch (packet)
            {
            case AccountFractionPacket accountFractionPacket:
                HandleChangeFraction(accountFractionPacket);
                break;

            case CheckCharacterAvailableNamePacket checkNamePacket:
                HandleCheckName(checkNamePacket);
                break;

            case CreateCharacterPacket createCharacterPacket:
                HandleCreateCharacter(createCharacterPacket);
                break;

            case SelectCharacterPacket selectCharacterPacket:
                HandleSelectCharacter(selectCharacterPacket);
                break;

            case DeleteCharacterPacket characterDeletePacket:
                HandleDeleteCharacter(characterDeletePacket);
                break;

            case RestoreCharacterPacket restoreCharacterPacket:
                HandleRestoreCharacter(restoreCharacterPacket);
                break;

            case RenameCharacterPacket renameCharacterPacket:
                HandleRenameCharacter(renameCharacterPacket);
                break;
            }
        }
示例#2
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            switch (packet)
            {
            case DuelRequestPacket duelRequestPacket:
                HandleDuelRequest(duelRequestPacket.DuelToWhomId);
                break;

            case DuelResponsePacket duelResponsePacket:
                HandleDuelResponse(duelResponsePacket.IsDuelApproved);
                break;

            case DuelAddItemPacket duelAddItemPacket:
                HandleAddItem(duelAddItemPacket.Bag, duelAddItemPacket.Slot, duelAddItemPacket.Quantity, duelAddItemPacket.SlotInTradeWindow);
                break;

            case DuelRemoveItemPacket duelRemoveItemPacket:
                HandleRemoveItem(duelRemoveItemPacket.SlotInTradeWindow);
                break;

            case DuelAddMoneyPacket duelAddMoneyPacket:
                HandleAddMoney(duelAddMoneyPacket.Money);
                break;

            case DuelOkPacket duelOkPacket:
                HandleDuelWindowClick(duelOkPacket.Result);
                break;
            }
        }
示例#3
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            switch (packet)
            {
            case TradeRequestPacket tradeRequestPacket:
                HandleTradeRequestPacket((WorldClient)sender, tradeRequestPacket.TradeToWhomId);
                break;

            case TradeResponsePacket tradeResponsePacket:
                if (tradeResponsePacket.IsDeclined)
                {
                    // TODO: do something with decline?
                }
                else
                {
                    var client         = (WorldClient)sender;
                    var tradeReceiver  = _gameWorld.Players[client.CharID];
                    var tradeRequester = tradeReceiver.TradePartner;

                    StartTrade(tradeRequester, tradeReceiver);
                }
                break;

            case TradeAddItemPacket tradeAddItemPacket:
                AddedItemToTrade((WorldClient)sender, tradeAddItemPacket);
                break;

            case TradeAddMoneyPacket tradeAddMoneyPacket:
                AddMoneyToTrade((WorldClient)sender, tradeAddMoneyPacket);
                break;

            case TradeDecidePacket tradeDecidePacket:
                if (tradeDecidePacket.IsDecided)
                {
                    TraderDecideConfirm((WorldClient)sender);
                }
                else
                {
                    TradeDecideDecline((WorldClient)sender);
                }
                break;

            case TradeFinishPacket tradeFinishPacket:
                if (tradeFinishPacket.Result == 2)
                {
                    TradeCancel((WorldClient)sender);
                }
                else if (tradeFinishPacket.Result == 1)
                {
                    TradeConfirmDeclined((WorldClient)sender);
                }
                else if (tradeFinishPacket.Result == 0)
                {
                    TradeConfirmed((WorldClient)sender);
                }
                break;
            }
        }
示例#4
0
 private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
 {
     switch (packet)
     {
     case CharacterEnteredMapPacket enteredMapPacket:
         LoadPlayerInMap(((WorldClient)sender).CharID);
         break;
     }
 }
示例#5
0
        private async void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            if (packet is HandshakePacket)
            {
                var handshake = (HandshakePacket)packet;
                (sender as WorldClient).SetClientUserID(handshake.UserId);

                // As soon as we change id, we should update id in dictionary.
                clients.TryRemove(sender.Id, out var client);
                SelectionScreenManagers.Remove(sender.Id, out var manager);

                // Now give client new id.
                client.Id = handshake.SessionId;

                // Return client back to dictionary.
                clients.TryAdd(client.Id, client);
                SelectionScreenManagers.Add(client.Id, manager);

                // Send request to login server and get client key.
                using var requestPacket = new Packet(PacketType.AES_KEY_REQUEST);
                requestPacket.Write(sender.Id.ToByteArray());
                InterClient.SendPacket(requestPacket);
            }

            if (packet is PingPacket)
            {
                // TODO: implement disconnect, if client is not sending ping packet.
            }

            if (packet is CashPointPacket)
            {
                // TODO: implement cash point packet.
                using var dummyPacket = new Packet(PacketType.CASH_POINT);
                dummyPacket.Write(0);
                sender.SendPacket(dummyPacket);
            }

            if (packet is LogOutPacket)
            {
                // TODO: For sure, here should be timer!
                await Task.Delay(1000 * 10); // 10 seconds * 1000 milliseconds

                if (sender.IsDispose)
                {
                    return;
                }

                using var logoutPacket = new Packet(PacketType.LOGOUT);
                sender.SendPacket(logoutPacket);

                sender.CryptoManager.UseExpandedKey = false;

                SelectionScreenManagers[sender.Id].SendSelectionScrenInformation(((WorldClient)sender).UserID);
            }
        }
示例#6
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            if (packet is LoginHandshakePacket)
            {
                var handshakePacket = (LoginHandshakePacket)packet;
                var decryptedNumber = sender.CryptoManager.DecryptRSA(handshakePacket.EncyptedNumber);
                sender.CryptoManager.GenerateAES(decryptedNumber);

                _interServer.Sessions.TryAdd(sender.Id, new KeyPair(sender.CryptoManager.Key, sender.CryptoManager.IV));
            }
        }
示例#7
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            if (packet is LoginHandshakePacket)
            {
                var handshakePacket = (LoginHandshakePacket)packet;
                var decryptedNumber = sender.CryptoManager.DecryptRSA(handshakePacket.EncyptedNumber);
                sender.CryptoManager.GenerateAES(decryptedNumber);

                InterServer.LoginClients.TryAdd(sender.Id, (LoginClient)sender);
            }
        }
示例#8
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            switch (packet)
            {
            case AuthenticationPacket authenticationPacket:
                HandleAuthentication(authenticationPacket);
                break;

            case SelectServerPacket selectServerPacket:
                HandleSelectServer(selectServerPacket);
                break;
            }
        }
示例#9
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            if (packet is AuthenticateServerPacket)
            {
                var authPacket = (AuthenticateServerPacket)packet;
                (sender as ISClient).SetWordServerInfo(authPacket.WorldServerInfo);
            }

            // World serber requests keys of loginc client.
            if (packet is AesKeyRequestPacket)
            {
                var aesRequestPacket = (AesKeyRequestPacket)packet;
                LoginClients.TryGetValue(aesRequestPacket.Guid, out var loginClient);
                ISPacketFactory.SendAuthentication(sender, loginClient);

                // Remove login client as soon as it's sent. We don't need it anymore.
                LoginClients.TryRemove(loginClient.Id, out var removed);
            }
        }
示例#10
0
        private void InterClient_OnPacketArrived(IDeserializedPacket packet)
        {
            // Packet, that login server sends, when user tries to connect world server.
            if (packet is AesKeyResponsePacket)
            {
                var aesPacket = (AesKeyResponsePacket)packet;

                clients.TryGetValue(aesPacket.Guid, out var worldClient);

                worldClient.CryptoManager.GenerateAES(aesPacket.Key, aesPacket.IV);

                // Maybe I need to refactor this?
                using var sendPacket = new Packet(PacketType.GAME_HANDSHAKE);
                sendPacket.WriteByte(0); // 0 means there was no error.
                sendPacket.WriteByte(2); // no idea what is it, it just works.
                sendPacket.Write(CryptoManager.XorKey);
                worldClient.SendPacket(sendPacket);

                SelectionScreenManagers[worldClient.Id].SendSelectionScrenInformation(worldClient.UserID);
            }
        }
示例#11
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            var worldSender = (WorldClient)sender;

            switch (packet)
            {
            case PartyRequestPacket partyRequestPacket:
                if (_gameWorld.Players.TryGetValue(partyRequestPacket.CharacterId, out var requestedPlayer))
                {
                    requestedPlayer.PartyInviterId = worldSender.CharID;
                    SendPartyRequest(requestedPlayer.Client, worldSender.CharID);
                }
                break;

            case PartyResponsePacket responsePartyPacket:
                if (_gameWorld.Players.TryGetValue(responsePartyPacket.CharacterId, out var partyResponser))
                {
                    if (responsePartyPacket.IsDeclined)
                    {
                        if (_gameWorld.Players.TryGetValue(partyResponser.PartyInviterId, out var partyRequester))
                        {
                            SendDeclineParty(partyRequester.Client, worldSender.CharID);
                        }
                    }
                    else
                    {
                        if (_gameWorld.Players.TryGetValue(partyResponser.PartyInviterId, out var partyRequester))
                        {
                            if (partyRequester.Party is null)
                            {
                                var party = new Party();
                                partyRequester.Party = party;
                                partyResponser.Party = party;
                            }
                            else
                            {
                                partyResponser.Party = partyRequester.Party;
                            }
                        }
                    }

                    partyResponser.PartyInviterId = 0;
                }
                break;

            case PartyLeavePacket partyLeavePacket:
                if (_gameWorld.Players.TryGetValue(worldSender.CharID, out var partyLeaver))
                {
                    partyLeaver.Party.LeaveParty(partyLeaver);
                }
                break;

            case PartyKickPacket partyKickPacket:
                if (_gameWorld.Players.TryGetValue(worldSender.CharID, out var leader))
                {
                    if (!leader.IsPartyLead)
                    {
                        return;
                    }

                    var playerToKick = leader.Party.Members.FirstOrDefault(m => m.Id == partyKickPacket.CharacterId);
                    if (playerToKick != null)
                    {
                        leader.Party.KickMember(playerToKick);
                    }
                }
                break;

            case PartyChangeLeaderPacket changeLeaderPacket:
                if (_gameWorld.Players.TryGetValue(worldSender.CharID, out var partyLeader))
                {
                    if (!partyLeader.IsPartyLead)
                    {
                        return;
                    }

                    var newLeader = partyLeader.Party.Members.FirstOrDefault(m => m.Id == changeLeaderPacket.CharacterId);
                    if (newLeader != null)
                    {
                        partyLeader.Party.SetLeader(newLeader);
                    }
                }
                break;
            }
        }
示例#12
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            var worldSender = (IWorldClient)sender;

            switch (packet)
            {
            case PartyRequestPacket partyRequestPacket:
                RequestParty(worldSender.CharID, partyRequestPacket.CharacterId);
                break;

            case PartyResponsePacket responsePartyPacket:
                if (_gameWorld.Players.TryGetValue(responsePartyPacket.CharacterId, out var partyResponser))
                {
                    if (responsePartyPacket.IsDeclined)
                    {
                        if (_gameWorld.Players.TryGetValue(partyResponser.PartyInviterId, out var partyRequester))
                        {
                            SendDeclineParty(partyRequester.Client, worldSender.CharID);
                        }
                    }
                    else
                    {
                        if (_gameWorld.Players.TryGetValue(partyResponser.PartyInviterId, out var partyRequester))
                        {
                            if (partyRequester.Party is null)
                            {
                                var party = new Party();
                                partyRequester.SetParty(party);
                                partyResponser.SetParty(party);
                            }
                            else
                            {
                                partyResponser.SetParty(partyRequester.Party);
                            }
                        }
                    }

                    partyResponser.PartyInviterId = 0;
                }
                break;

            case PartyLeavePacket partyLeavePacket:
                _player.SetParty(null);
                break;

            case PartyKickPacket partyKickPacket:
                if (!_player.IsPartyLead)
                {
                    return;
                }

                var playerToKick = _player.Party.Members.FirstOrDefault(m => m.Id == partyKickPacket.CharacterId);
                if (playerToKick != null)
                {
                    _player.Party.KickMember(playerToKick);
                    playerToKick.SetParty(null, true);
                }
                break;

            case PartyChangeLeaderPacket changeLeaderPacket:
                if (!_player.IsPartyLead)
                {
                    return;
                }

                var newLeader = _player.Party.Members.FirstOrDefault(m => m.Id == changeLeaderPacket.CharacterId);
                if (newLeader != null)
                {
                    _player.Party.Leader = newLeader;
                }
                break;

            case PartySearchInvitePacket partySearchInvitePacket:
                var requestedPlayer = _player.Map.PartySearchers.FirstOrDefault(p => p.Name == partySearchInvitePacket.Name);
                if (requestedPlayer != null && requestedPlayer.Party is null)
                {
                    RequestParty(worldSender.CharID, requestedPlayer.Id);
                }
                break;

            case RaidCreatePacket raidCreatePacket:
                if (!_player.IsPartyLead)
                {
                    return;
                }
                var raid    = new Raid(raidCreatePacket.AutoJoin, (RaidDropType)raidCreatePacket.DropType);
                var members = _player.Party.Members.ToList();
                foreach (var member in members)
                {
                    member.SetParty(raid, true);
                }
                raid.Leader = _player;
                foreach (var m in members)
                {
                    SendRaidCreated(m.Client, raid);
                }
                break;

            case RaidDismantlePacket raidDismantlePacket:
                if (!_player.IsPartyLead || !(_player.Party is Raid))
                {
                    return;
                }
                _player.Party.Dismantle();
                break;

            case RaidLeavePacket raidLeavePacket:
                _player.SetParty(null);
                break;

            case RaidChangeAutoInvitePacket raidChangeAutoInvitePacket:
                if (!_player.IsPartyLead || !(_player.Party is Raid))
                {
                    return;
                }
                (_player.Party as Raid).ChangeAutoJoin(raidChangeAutoInvitePacket.IsAutoInvite);
                break;

            case RaidChangeLootPacket raidChangeLootPacket:
                if (!_player.IsPartyLead || !(_player.Party is Raid))
                {
                    return;
                }
                (_player.Party as Raid).ChangeDropType((RaidDropType)raidChangeLootPacket.LootType);
                break;

            case RaidJoinPacket raidJoinPacket:
                if (_player.Party != null)     // Player is already in party.
                {
                    SendPartyError(_player.Client, PartyErrorType.RaidNotFound);
                    return;
                }

                var raidMember = _gameWorld.Players.Values.FirstOrDefault(m => m.Name == raidJoinPacket.CharacterName);
                if (raidMember is null || raidMember.Country != _player.Country || !(raidMember.Party is Raid))
                {
                    SendPartyError(_player.Client, PartyErrorType.RaidNotFound);
                }
                else
                {
                    if ((raidMember.Party as Raid).AutoJoin)
                    {
                        _player.SetParty(raidMember.Party);
                        if (_player.Party is null)
                        {
                            SendPartyError(_player.Client, PartyErrorType.RaidNoFreePlace);
                        }
                    }
                    else
                    {
                        SendPartyError(_player.Client, PartyErrorType.RaidNoAutoJoin);
                    }
                }
                break;