Пример #1
0
        public void Disconnect()
        {
            if (account.authenticated == true)
            {
                if (clientType == "Battle")
                {
                    Battle battle = BattleAPI.GetBattle(account.username);

                    if (battle.phase == "End")
                    {
                        BattleAPI.RemoveBattle(account.username);
                    }
                    else
                    {
                        if (!PlayerAPI.IsOnline(battle.opponent))
                        {
                            BattleAPI.RemoveBattle(battle.opponent);
                            BattleAPI.RemoveBattle(account.username);
                        }
                        else
                        {
                            BattleAPI.Message(battle, "Scrolls", account.username + " has disconnected!");
                        }
                    }
                }
                if (clientType == "Lobby")
                {
                    if (account.tradeStatus.trading)
                    {
                        Client opponentSession = PlayerAPI.GetSession(account.tradeStatus.partner, false);

                        if (opponentSession != null)
                        {
                            opponentSession.account.tradeStatus.trading = false;

                            TradeResponse tradeResponse = new TradeResponse();
                            tradeResponse.status = "CANCEL_BARGAIN";

                            if (account.tradeStatus.initiator)
                            {
                                tradeResponse.from = PlayerAPI.UserInfo(this);
                                tradeResponse.to   = PlayerAPI.UserInfo(opponentSession);
                            }
                            else
                            {
                                tradeResponse.from = PlayerAPI.UserInfo(opponentSession);
                                tradeResponse.to   = PlayerAPI.UserInfo(this);
                            }

                            opponentSession.Send(tradeResponse);

                            RoomAPI.Message("trade-" + account.tradeStatus.tradeId, "Scrolls", "Trade ended (partner withdrew).");
                        }
                    }

                    foreach (string roomName in account.chatroomList)
                    {
                        RoomAPI.RemovePlayer(roomName, account.username);
                    }
                }

                int lastId;
                DB.Database.Execute(connection, out lastId, true, true, "UPDATE account SET signedIn = 0 WHERE guid = ?", account.id);

                Variables.sessionMap.Remove(account.username);
                connection.Dispose();
            }
        }
Пример #2
0
        public static void TradeCancel(Client client)
        {
            client.packetMap.Remove("TradeCancel");

            if (client.account.tradeStatus.trading)
            {
                Client opponentSession = PlayerAPI.GetSession(client.account.tradeStatus.partner, false);

                if (opponentSession != null)
                {
                    client.account.tradeStatus.trading          = false;
                    opponentSession.account.tradeStatus.trading = false;

                    TradeResponse tradeResponse = new TradeResponse();
                    tradeResponse.status = "CANCEL_BARGAIN";

                    if (client.account.tradeStatus.initiator)
                    {
                        tradeResponse.from = PlayerAPI.UserInfo(client);
                        tradeResponse.to   = PlayerAPI.UserInfo(opponentSession);
                    }
                    else
                    {
                        tradeResponse.from = PlayerAPI.UserInfo(opponentSession);
                        tradeResponse.to   = PlayerAPI.UserInfo(client);
                    }

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

                    RoomAPI.Message("trade-" + client.account.tradeStatus.tradeId, "Scrolls", "Trade ended.");
                }
            }
        }
Пример #3
0
        public static void TradeDecline(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("TradeDecline");

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

            if (opponentSession != null)
            {
                if (opponentSession.account.tradeRequestList.Contains(client.account.username))
                {
                    TradeResponse tradeResponse = new TradeResponse();
                    tradeResponse.status = "DECLINE";
                    tradeResponse.from   = PlayerAPI.UserInfo(opponentSession);
                    tradeResponse.to     = PlayerAPI.UserInfo(client);

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

                    opponentSession.account.tradeRequestList.Remove(client.account.username);
                }
            }
        }
Пример #4
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);
                }
            }
        }