Пример #1
0
        /// <summary>
        /// Client sends auth token after succesful connection to game server
        /// This method checks if token is correct
        /// and marks user as authorized.
        /// Also sends Send_ErrorBadAuthToken and Send_AuthorizedOk
        /// </summary>
        /// <param name="connectionId">User who sent</param>
        /// <param name="tokenString">user's token string</param>
        /// <returns>true on succesful connect, false on fail</returns>
        public static bool AuthorizeClientOnGameServer(long connectionId, int tokenHash)
        {
            Client client = ClientManager.GetConnectedClient(connectionId);

            // If client was already authorized then ignore.
            // It will be true if client did suddenly lost connection
            // and then reconnected in a short period of time
            // he will use the same tocken in this case
            if (client.Authorized)
            {
                // Send OK message to client
                ServerSendPackets.Send_AuthorizedOk(connectionId);
                ServerSendPackets.Send_UpdateUserData(connectionId);
                return(true);
            }

            // get token from manager if exists
            Token token = TokenManager.UseToken(tokenHash);

            // if token doesn't exist then send error
            if (token == null)
            {
                ServerSendPackets.Send_ErrorBadAuthToken(connectionId);
                return(false);
            }


            // Authorized OK
            client.Authorize(token);
            // Send OK message to client
            ServerSendPackets.Send_AuthorizedOk(connectionId);
            ServerSendPackets.Send_UpdateUserData(connectionId);

            return(true);
        }
Пример #2
0
        public static void AddMoney(long userId, double sum)
        {
            var user = DatabaseOperations.GetUserById(userId);

            // create new command
            var command = new MySqlCommand();

            command.CommandText = "UPDATE foolonline.accounts SET `Money`= `Money` + @reward WHERE UserId=@userId";
            command.Parameters.AddWithValue("@reward", sum);
            command.Parameters.AddWithValue("@userId", userId);

            // execute
            DatabaseConnection.ExecuteNonQuery(command);

            var client = ClientManager.GetConnectedClientByUserId(userId);

            if (client != null)
            {
                client.UserData.Money += sum;
                ServerSendPackets.Send_UpdateUserData(client.ConnectionId);
            }
        }