Пример #1
0
        public static void LibraryView(Client client)
        {
            client.packetMap.Remove("LibraryView");

            LibraryView libraryView = new LibraryView();
            libraryView.profileId   = client.account.id;

            foreach (KeyValuePair<int, Card> cardServer in client.account.cardMap)
            {
                libraryView.cards.Add(cardServer.Value);
            }

            client.Send(libraryView);
        }
Пример #2
0
        public static void TradeAccept(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("TradeAccept");

            TradeAccept tradeAccept = JsonConvert.DeserializeObject<TradeAccept>(jsonPacketData);
            Client opponentSession = PlayerAPI.GetSession(tradeAccept.inviter, true);

            if (opponentSession != null)
            {
                if (opponentSession.account.tradeRequestList.Contains(client.account.username) && !opponentSession.account.tradeStatus.trading)
                {
                    //Note: Trade ID generation is temporary
                    Random random = new Random();
                    int tradeId = random.Next(1000000, 9999999);

                    client.account.tradeStatus.trading            = true;
                    client.account.tradeStatus.partner            = opponentSession.account.username;
                    client.account.tradeStatus.tradeId            = tradeId;
                    client.account.tradeStatus.initiator          = false;

                    opponentSession.account.tradeStatus.trading   = true;
                    opponentSession.account.tradeStatus.partner   = client.account.username;
                    opponentSession.account.tradeStatus.tradeId   = tradeId;
                    opponentSession.account.tradeStatus.initiator = true;

                    TradeResponse tradeResponse = new TradeResponse();
                    tradeResponse.status = "ACCEPT";
                    tradeResponse.from   = PlayerAPI.UserInfo(opponentSession);
                    tradeResponse.to     = PlayerAPI.UserInfo(client);

                    client.Send(tradeResponse);
                    opponentSession.Send(tradeResponse);

                    LibraryView libraryView = new LibraryView();
                    libraryView.profileId = client.account.id;

                    foreach (KeyValuePair<int, Card> card in client.account.cardMap)
                    {
                        libraryView.cards.Add(card.Value);
                    }

                    client.Send(libraryView);
                    opponentSession.Send(libraryView);

                    LibraryView libraryViewOpponent = new LibraryView();
                    libraryViewOpponent.profileId = opponentSession.account.id;

                    foreach (KeyValuePair<int, Card> card in opponentSession.account.cardMap)
                    {
                        libraryViewOpponent.cards.Add(card.Value);
                    }

                    client.Send(libraryViewOpponent);
                    opponentSession.Send(libraryViewOpponent);

                    string roomName = "trade-" + tradeId;

                    if (!RoomAPI.Exists(roomName))
                    {
                        RoomAPI.Add(roomName);
                    }

                    RoomAPI.JoinRoom(client, roomName);
                    RoomAPI.JoinRoom(opponentSession, roomName);

                    opponentSession.account.tradeRequestList.Remove(client.account.username);
                }
            }
        }