Ejemplo n.º 1
0
        public void CreateAccountForUser(string fbAccountId, string fbSessionKey, string nickName, string firstName, string lastName, string userIpAddress, string campaignId, string referrerId, Action <ServerAccount> createAccountForUserCallback)
        {
            mLogger.Debug(String.Format("CreateAccountForUser {0} {1} {2} {3} {4} {5} {6} {7}", fbAccountId, fbSessionKey, nickName, firstName, lastName, userIpAddress, campaignId, referrerId));
            Action <XmlDocument> createServerAccountServiceCallback = delegate(XmlDocument receivedXmlCreateNewAccount)
            {
                XmlNode newAccountXmlNode = receivedXmlCreateNewAccount.SelectSingleNode("Accounts/Account");
                //if we get a null xml node when trying to create an account, we need to throw an error
                if (newAccountXmlNode == null)
                {
                    StateServerAssert.Assert(new System.Exception("Error: unable to create a new account.. do you have a valid facebook Account Id, Session key, nickname, firstname, lastname, campaignId, and referredId?  Check your client data file! Returned Xml: " + receivedXmlCreateNewAccount.OuterXml));
                    createAccountForUserCallback(null);
                }
                else
                {
                    ServerAccount serverAccount = AccountsXmlUtil.GetAccountFromXml(newAccountXmlNode);
                    serverAccount.IpAddress = userIpAddress;
                    SaveCurrentAccountData(serverAccount);
                    CreatePaymentItemAccountForUser(serverAccount, userIpAddress, createAccountForUserCallback);

                    Metrics.Log(LogGlobals.CATEGORY_ACCOUNT, LogGlobals.EVENT_ACCOUNT_CREATED, LogGlobals.ACCOUNT_ID_LABEL, serverAccount.AccountId.ToString(), serverAccount.AccountId.ToString());
                }
            };

            CallCreateServerAccountService(fbAccountId, fbSessionKey, nickName, firstName, lastName, userIpAddress, campaignId, referrerId, createServerAccountServiceCallback);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle an event log message from the client
        /// </summary>
        /// <param name="message"></param>
        public static void Log(Message receivedMessage, string accountId)
        {
            string categoryName = (string)receivedMessage.Data[0];
            string eventName    = (string)receivedMessage.Data[1];
            string subEvent     = (string)receivedMessage.Data[2];
            string eventData    = (string)receivedMessage.Data[3];

            Metrics.Log(categoryName, eventName, subEvent, eventData, accountId);
        }
Ejemplo n.º 3
0
        private void JoinRoomForClient(Message receivedMessage, Guid senderId)
        {
            RoomId         newRoomId       = CheckType.TryAssignType <RoomId>(receivedMessage.Data[0]);
            MessageSubType roomRequestType = CheckType.TryAssignType <MessageSubType>(receivedMessage.Data[1]);


            JoinRoom(senderId, newRoomId, delegate()
            {
                AccountId accountId = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(senderId).AccountId;
                Metrics.Log(LogGlobals.CATEGORY_ROOMS, LogGlobals.ROOM_ENTERED, LogGlobals.ROOM_LABEL, newRoomId.ToString(), accountId.ToString());
                SendClientAvailableRooms(senderId, roomRequestType);
            });
        }
Ejemplo n.º 4
0
        private void LoginError(Guid sessionId, ErrorIndex errorIndex, MessageSubType errorActionType)
        {
            ServerAccount serverAccount = mSessionManager.GetServerAccountFromSessionId(sessionId);
            string        accountId     = "unknown account";

            if (serverAccount != null)
            {
                accountId = serverAccount.AccountId.ToString();
            }
            mLogger.Warn(String.Format("LoginError | sessionId={0} | accountId={1}", sessionId, accountId));
            Metrics.Log(LogGlobals.CATEGORY_CONNECTION, LogGlobals.EVENT_LOGIN, LogGlobals.LOGIN_FAILED, accountId);
            Message loginErrorMessage = StateServerError.ErrorToUser(errorIndex, errorActionType);

            SendMessageToReflector(loginErrorMessage, sessionId);
            DisconnectUser(sessionId);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create the PaymentItem Account for a user
        /// </summary>
        /// <param name="accountXmlNode">The account information xml node</param>
        /// <param name="serverAccount">The account object </param>
        /// <param name="accountForUserCallback">The callback to call when finished</param>
        public virtual void CreatePaymentItemAccountForUser(ServerAccount serverAccount, string userIpAddress, Action <ServerAccount> accountForUserCallback)
        {
            mLogger.Debug("CreatePaymentItemAccountForUser " + serverAccount.AccountId.ToString());
            try
            {
                PaymentItemsProcess paymentItems = new PaymentItemsProcess();
                UserInfo            userInfo     = GetPaymentItemsUserInfo(serverAccount, userIpAddress);
                int initialCoinAmount            = GetPaymentItemsUserInfoUserInitialCoinAmount();
                int initialCashAmount            = GetPaymentItemsUserInfoUserInitialCashAmount();

                System.Action <string> asyncCallback = delegate(string paymentItemsResponse)
                {
                    try
                    {
                        XmlDocument response = new XmlDocument();
                        response.LoadXml(paymentItemsResponse);

                        if (response != null)
                        {
                            XmlNode userNode = response.SelectSingleNode("Response/user");
                            serverAccount.PaymentItemUserId    = userNode.Attributes["id"].InnerText;
                            serverAccount.PaymentItemSecureKey = userNode.Attributes["secureKey"].InnerText;

                            UpdateServerPaymentItemsAccount(serverAccount, accountForUserCallback);
                            Metrics.Log(LogGlobals.CATEGORY_ACCOUNT, LogGlobals.EVENT_PAYMENT_ACCOUNT_CREATED, LogGlobals.PAYMENT_ACCOUNT_ID_LABEL, serverAccount.PaymentItemUserId, serverAccount.AccountId.ToString());
                        }
                    }

                    //if twoFish account creation blows an exception the we do not want to cause the game to fail
                    //so lets just continue
                    catch (System.Exception ex)
                    {
                        accountForUserCallback(serverAccount);
                    }
                };


                paymentItems.CreateNewUser(userInfo, initialCoinAmount, initialCashAmount, asyncCallback);
            }

            //if twoFish account creation blows an exception the we do not want to cause the game to fail
            //so lets just continue
            catch
            {
                accountForUserCallback(serverAccount);
            }
        }
Ejemplo n.º 6
0
 public bool AddSession(Guid sessionId, ServerAccount serverAccount)
 {
     if (mSessionIdsToServerAccounts.ContainsKey(sessionId))
     {
         mLogger.Warn("WARNING: SessionManager already contains sessionId " + sessionId.ToString() + " in mSessionIdsToServerAccounts");
         return(false);
     }
     mSessionIdsToServerAccounts.Add(sessionId, serverAccount);
     Metrics.Log(LogGlobals.CATEGORY_CONNECTION, LogGlobals.EVENT_CONNECTED, serverAccount.AccountId.ToString());
     if (mAccountIdsToServerAccounts.ContainsKey(serverAccount.AccountId))
     {
         mLogger.Warn("WARNING: SessionManager already contains accountId " + serverAccount.AccountId.ToString() + " in mAccountIdsToServerAccounts");
         return(false);
     }
     mAccountIdsToServerAccounts.Add(serverAccount.AccountId, serverAccount);
     return(true);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Process the accept for the socket listener.
        /// </summary>
        /// <param name="e">SocketAsyncEventArg associated with the completed accept operation.</param>
        private void ProcessNewClientConnection(Socket connectingClientSocket)          /*SocketAsyncEventArgs e)*/
        {
            EnforceSingleThread();

            Connection connection = null;

            ++mNumConnectedSockets;

            mLogger.Info("Client connected    (" + ((IPEndPoint)connectingClientSocket.RemoteEndPoint).Address + ").     Total concurrent: " + mNumConnectedSockets);
            Metrics.Log(LogGlobals.CATEGORY_SERVER_STATS, LogGlobals.CONCURRENCY, "Connections", mNumConnectedSockets.ToString(), "");

            Guid sessionId = Guid.NewGuid();

            connection = new Connection(connectingClientSocket, sessionId, CloseClientSocket);

            mConnectionManager.AddConnection(connection);
        }
Ejemplo n.º 8
0
        private void SwitchRoomForClient(Message receivedMessage, Guid senderId)
        {
            RoomId         newRoomId       = CheckType.TryAssignType <RoomId>(receivedMessage.Data[0]);
            MessageSubType roomRequestType = CheckType.TryAssignType <MessageSubType>(receivedMessage.Data[1]);

            ServerAccount account   = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(senderId);
            RoomId        oldRoomId = account.LastRoomId;

            SwitchRoom(senderId, newRoomId, oldRoomId, delegate()
            {
                string newRoom = "";
                if (newRoomId != null)
                {
                    newRoom = newRoomId.ToString();
                }
                Metrics.Log(LogGlobals.CATEGORY_ROOMS, LogGlobals.ROOM_ENTERED, LogGlobals.ROOM_LABEL, newRoom, account.AccountId.ToString());
                SendClientAvailableRooms(senderId, roomRequestType);
            }
                       );
        }
Ejemplo n.º 9
0
        public void CreateNewAvatarForAccount(Guid sessionId, ZoneId zoneId, ServerAccount serverAccount, AvatarId defaultAvatarId, System.Action <bool> createAvatarFinishedCallback)
        {
            Action <XmlDocument> createAvatarServiceCallback = delegate(XmlDocument xmlResponse)
            {
                XmlNode avatarXmlNode = xmlResponse.SelectSingleNode("Avatars/Avatar");

                if (avatarXmlNode != null)
                {
                    Metrics.Log(LogGlobals.CATEGORY_ACCOUNT, LogGlobals.EVENT_AVATAR_CREATED, LogGlobals.AVATAR_ID_LABEL, defaultAvatarId.ToString(), serverAccount.AccountId.ToString());
                    GetAvatarServiceResponse(avatarXmlNode, serverAccount.Nickname, sessionId, zoneId, createAvatarFinishedCallback);
                }
                else
                {
                    StateServerAssert.Assert(new System.Exception("Error: Could not create avatar: " + xmlResponse.InnerText));
                    createAvatarFinishedCallback(false);
                }
            };

            AvatarManagerServiceAPI.CreateAvatarForUser(serverAccount, defaultAvatarId, createAvatarServiceCallback);
        }
Ejemplo n.º 10
0
        public bool RemoveSession(Guid sessionId)
        {
            ServerAccount serverAccountToRemove = null;

            if (mSessionIdsToServerAccounts.TryGetValue(sessionId, out serverAccountToRemove))
            {
                Metrics.Log(LogGlobals.CATEGORY_CONNECTION, LogGlobals.EVENT_DISCONNECTED, "ElapsedTime", serverAccountToRemove.LoggedInTimeLength.ToString(), serverAccountToRemove.AccountId.ToString());
                mAccountIdsToServerAccounts.Remove(serverAccountToRemove.AccountId);
            }
            bool containedSession = mSessionIdsToServerAccounts.Remove(sessionId);

            List <ZoneId> zonesToProcess = GetZoneIdsFromInterestedSessionId(sessionId);

            foreach (ZoneId zoneId in zonesToProcess)
            {
                List <Guid> sessions = GetSessionIdsInterestedInZoneId(zoneId);
                sessions.Remove(sessionId);
            }

            mSessionsIdsToZoneIdInterests.Remove(sessionId);
            return(containedSession);
        }
Ejemplo n.º 11
0
        private void LoginSuccess(Guid sessionId, Stopwatch loginTimer)
        {
            List <object> loginSuccessMessageData = new List <object>();
            ServerAccount serverAccount           = mSessionManager.GetServerAccountFromSessionId(sessionId);

            if (serverAccount != null)
            {
                loginSuccessMessageData.Add(sessionId);
                loginSuccessMessageData.Add(serverAccount.UserProperties);
                loginSuccessMessageData.Add(serverAccount.AccountId);

                Message loginSuccessMessage = new Message(MessageType.Connect, MessageSubType.SuccessfulLogin, loginSuccessMessageData);

                SendMessageToReflector(loginSuccessMessage, sessionId);
                Metrics.Log(LogGlobals.CATEGORY_CONNECTION, LogGlobals.EVENT_LOGIN, LogGlobals.LOGIN_SUCCESS, serverAccount.AccountId.ToString());
                loginTimer.Stop();
                mLogger.InfoFormat("LoginSuccess |sessionId={0} | accountId={1} | Time Taken={2}", sessionId, serverAccount.AccountId.ToString(), loginTimer.Elapsed.Duration());
            }
            else
            {
                LoginError(sessionId, ErrorIndex.CannotGetAccountFromSessionManager, MessageSubType.UserLoginCannotGetAccountFromSessionManagerError);
            }
        }
Ejemplo n.º 12
0
        //sender Id is assigned at the socketListener and is the message sender's sessionId
        protected void ProcessMessage(Message receivedMessage, Guid senderId, List <Guid> recipients)
        {
            switch (receivedMessage.MessageType)
            {
            case MessageType.Connect:
                mServerStateMachine.ConnectionHandler.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.Event:
                ServerAccount account   = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(senderId);
                string        accountId = "";
                if (account != null)
                {
                    accountId = account.AccountId.ToString();
                }
                Metrics.Log(receivedMessage, accountId);
                break;

            case MessageType.Create:
                break;

            case MessageType.Update:
                mServerStateMachine.ServerObjectRepository.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.Room:
                mServerStateMachine.RoomManager.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.Friends:
                mServerStateMachine.FriendsManager.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.Admin:
                mServerStateMachine.AdminManager.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.PaymentItems:
                mServerStateMachine.PaymentItemsManager.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.FashionMinigame:
                mServerStateMachine.FashionMinigameServer.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.Account:
                mServerStateMachine.UsersManager.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.AssetRepository:
                mServerStateMachine.ServerAssetRepository.ReceiveRequest(receivedMessage, senderId);
                break;

            case MessageType.Heartbeat:
                //answer the heartbeat call
                ProcessHeartbeatMessage(receivedMessage, senderId);
                break;

            case MessageType.Escrow:
                mServerStateMachine.EscrowManager.ReceiveRequest(receivedMessage, senderId);
                break;

            default:
                mLogger.Error("Unable to process a message with unexpected MessageType (" + receivedMessage.MessageType + ")");
                break;
            }
            //foreach (object o in receivedMessage.Data)
            //{
            //    Console.WriteLine(o.ToString() + " : " + o.GetType().ToString());
            //}
        }