コード例 #1
0
        internal static void AddSpectatorToMatch(string matchId, string clientId, string accountId, string username)
        {
            if (m_Matches.ContainsKey(matchId))
            {
                MatchState match = m_Matches[matchId];
                AccountHandler.GetAccountById(accountId).SetCurrentMatch(match);

                if (match.CanAddSpectator())
                {
                    MatchEventDispatcher.InvokeSpectatorJoinEvent
                        (new SpectatorJoinEventArgs(matchId, true, clientId));

                    PlayerState spectator = new PlayerState(accountId, username);

                    match.AddSpectator(spectator);

                    MatchEventDispatcher.InvokeSpectatorSyncEvent
                        (new SpectatorSyncEventArgs(match, spectator));

                    match.SyncAllNetStatesWithSpec(spectator);
                }

                else
                {
                    MatchEventDispatcher.InvokeSpectatorJoinEvent
                        (new SpectatorJoinEventArgs(matchId, false, clientId));
                }
            }
        }
コード例 #2
0
        internal static bool?UserRelationshipExists(string userId, string friendId)
        {
            try
            {
                using (MySqlConnection mySqlConnection = MySqlConnector.InitializeMySqlConnection())
                {
                    if (MySqlConnector.OpenConnection(mySqlConnection))
                    {
                        using (MySqlCommand c = new MySqlCommand(m_QueryFriendIdentityExistsString, mySqlConnection))
                        {
                            c.Parameters.Add(new MySqlParameter("?user", userId));
                            c.Parameters.Add(new MySqlParameter("?friend", friendId));

                            using (MySqlDataReader reader = c.ExecuteReader())
                            {
                                if (reader.Read())
                                {
                                    if (ServerCore.DebugMode)
                                    {
                                        Console.WriteLine("User Relationship [{1}] Does Not Exist For: {0}",
                                                          AccountHandler.GetAccountById(userId), AccountHandler.GetAccountById(friendId));
                                    }
                                    return(true);
                                }

                                else
                                if (ServerCore.DebugMode)
                                {
                                    Console.WriteLine("User Relationship [{1}] Already Exists For: {0}",
                                                      AccountHandler.GetAccountById(userId), AccountHandler.GetAccountById(friendId));
                                }
                            }
                        }

                        MySqlConnector.CloseConnection(mySqlConnection);
                    }

                    else
                    {
                        Console.WriteLine("[Error]: Unable To Contact Database During: (GetUserFriends).");
                        return(null);
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }

            return(false);
        }
コード例 #3
0
 private void HandleAccountLoginRequest_One(string id, string[] segments)
 {
     if (!AccountHandler.AccountOnline(segments[2]))
     {
         AccountDatabaseHandler.AttemptLogin(id, segments[2], segments[3]);
     }
     else
     {
         NetworkEventDispatcher.InvokeUserLoginEvent
             (new UserLoginEventArgs(id, segments[2], false, true));
     }
 }
コード例 #4
0
        internal static void SendMessageToClientByAccount(string id, string message)
        {
            Account account = AccountHandler.GetAccountById(id);

            if (account == null)
            {
                return;
            }

            if (m_ClientAccountPairs.ContainsKey(account))
            {
                m_ClientAccountPairs[account].SendData(message);
            }
        }
コード例 #5
0
        private void NetworkEventDispatcher_UserLoginEvent(UserLoginEventArgs args)
        {
            try
            {
                ClientState client = ClientManager.GetClientById(args.ClientId);
                if (client != null)
                {
                    if (args.Success)
                    {
                        Account account = new Account(args.ClientId, args.Username);
                        AccountHandler.AddOnlineAccount(account);

                        client.Authorize(account);

                        //0#|lgnsccs#|username#|email#|rating#|wins#|losses#|id
                        string s = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}{1}{7}{1}{8}",
                                                 (int)ReadProtocol.GetVersion(),
                                                 m_SegmentTerminator,
                                                 NetworkCommand.GetCommand(NetworkCommandType.LoginSuccess),
                                                 account.Username,
                                                 account.Email,
                                                 account.Rating,
                                                 account.Wins,
                                                 account.Losses,
                                                 account.AccountId);

                        client.SendData(s);

                        SendAllAccountSyncDataToClient(client, AccountSyncType.Connect);
                        SendAccountSyncDataToAllClients(account, client, AccountSyncType.Connect);

                        SyncUserFriends(account);
                        SyncAllAvailableMatchesWithClient(client);
                    }

                    else
                    {
                        string s = string.Format("{0}{1}{2}{1}{3}",
                                                 (int)ReadProtocol.GetVersion(),
                                                 m_SegmentTerminator,
                                                 NetworkCommand.GetCommand(NetworkCommandType.LoginFail),
                                                 args.LoggedIn.ToString());

                        client.SendData(s);
                    }
                }
            }

            catch (Exception e) { Console.WriteLine(e.ToString()); }
        }
コード例 #6
0
        internal static void AddPlayerToMatch(MatchState match, string accountId, string username)
        {
            try
            {
                match.AddPlayer(accountId, username);

                AccountHandler.GetAccountById(accountId).SetCurrentMatch(match);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #7
0
        private void HandlePrivateMessage_One(string[] segments)
        {
            //protocol#|pvtmsg#|from#|to#|time#|message
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}{1}{6}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.PrivateMessage),
                                       segments[2],
                                       segments[3],
                                       segments[4],
                                       segments[5]);

            ClientManager.SendMessageToClientByAccount
                (AccountHandler.GetAccountById(segments[3]), cmd);
        }
コード例 #8
0
        private void HandleMatchCreationEvent(MatchState match)
        {
            //protocol#|mtchcrtd#|matchId#|playerOneId#|playerOneUsername
            string cmd = string.Format("{0}{1}{2}{1}{3}{1}{4}{1}{5}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.MatchCreated),
                                       match.MatchIdentity,
                                       match.PlayerOne.AccountIdentity,
                                       match.PlayerOne.Username);

            MatchHandler.SendMessageToUsersInMatch(match, cmd);

            ClientState client = ClientManager.GetClientByAccount
                                     (AccountHandler.GetAccountById(match.PlayerOne.AccountIdentity));

            ClientManager.SendMessageToAllClients(cmd, client);
        }
コード例 #9
0
        private void HandleFriendRequest_One(string clientId, string[] segments)
        {
            //protocol#|frndrq#|id
            ClientState client = ClientManager.GetClientById(clientId);
            string      idTo   = segments[2];

            string cmd = string.Format("{0}{1}{2}{1}{3}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.FriendRequest),
                                       client.AccountRelative.AccountId);

            if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
            {
                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idTo), cmd);
            }
        }
コード例 #10
0
        private void HandleFriendAddition_One(string clientId, string[] segments)
        {
            try //protocol#|adfrnd#|id
            {
                string idFrom = ClientManager.GetClientById(clientId).AccountRelative.AccountId;
                string idTo   = segments[2];

                AccountDatabaseHandler.AddFriendRelationship(idFrom, idTo);
                AccountDatabaseHandler.AddFriendRelationship(idTo, idFrom);

                if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idFrom)))
                {
                    AccountHandler.GetAccountById(idFrom).AddFriend(idTo);
                }

                if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
                {
                    AccountHandler.GetAccountById(idTo).AddFriend(idFrom);
                }

                string cmd = string.Format("{0}{1}{2}{1}{3}",
                                           (int)ReadProtocol.GetVersion(),
                                           m_SegmentTerminator,
                                           NetworkCommand.GetCommand(NetworkCommandType.AddFriend),
                                           idTo);

                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idFrom), cmd);

                cmd = string.Format("{0}{1}{2}{1}{3}",
                                    (int)ReadProtocol.GetVersion(),
                                    m_SegmentTerminator,
                                    NetworkCommand.GetCommand(NetworkCommandType.AddFriend),
                                    idFrom);

                ClientManager.SendMessageToClientByAccount
                    (AccountHandler.GetAccountById(idTo), cmd);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #11
0
        internal void DisposeOfClientAndConnection()
        {
            try
            {
                ClientManager.RemoveClient(this);

                if (m_AccountRelative != null)
                {
                    AccountHandler.RemoveOnlineAccount(m_AccountRelative);
                }

                m_Socket.BeginDisconnect
                    (false, new AsyncCallback(DisconnectCallback), this);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #12
0
        private void HandleFriendRemoval_One(string clientId, string[] segments)
        {
            //protocol#|rmfrnd#|id
            string idTo   = segments[2];
            string idFrom = ClientManager.GetClientById(clientId).AccountRelative.AccountId;

            AccountDatabaseHandler.RemoveUserRelationships(idFrom, idTo);
            AccountDatabaseHandler.RemoveUserRelationships(idTo, idFrom);

            string cmd = string.Format("{0}{1}{2}{1}{3}",
                                       (int)ReadProtocol.GetVersion(),
                                       m_SegmentTerminator,
                                       NetworkCommand.GetCommand(NetworkCommandType.RemoveFriend),
                                       idFrom);

            if (AccountHandler.AccountOnline(AccountDatabaseHandler.GetAccountNameFromId(idTo)))
            {
                ClientManager.SendMessageToClientByAccount(AccountHandler.GetAccountById(idTo), cmd);
            }
        }
コード例 #13
0
        internal static void AddFriendRelationship(string userId, string friendId)
        {
            bool?relationshipExists = UserRelationshipExists(userId, friendId);

            if (relationshipExists != null && relationshipExists.Value == false)
            {
                try
                {
                    using (MySqlConnection mySqlConnection = MySqlConnector.InitializeMySqlConnection())
                    {
                        if (MySqlConnector.OpenConnection(mySqlConnection))
                        {
                            using (MySqlCommand c = new MySqlCommand(m_AddUserFriendRelationshipString, mySqlConnection))
                            {
                                c.Parameters.Add(new MySqlParameter("?userId", userId));
                                c.Parameters.Add(new MySqlParameter("?friendId", friendId));

                                int i = c.ExecuteNonQuery();

                                if (i > 0)
                                {
                                    Console.WriteLine("User Relationship Successfully Created For: {0}", AccountHandler.GetAccountById(userId).Username);
                                }

                                else
                                {
                                    Console.WriteLine("Failed To Create New User Relationship For: {0}", AccountHandler.GetAccountById(userId).Username);
                                }

                                MySqlConnector.CloseConnection(mySqlConnection);
                            }
                        }

                        else
                        {
                            Console.WriteLine("[Error]: Unable To Contact Database During: (CreateAccount).");
                        }
                    }
                }

                catch (Exception e) { Console.WriteLine(e.ToString()); }
            }
        }