コード例 #1
0
ファイル: LoginMessage.cs プロジェクト: nako75/UCS-4
        void LogUser()
        {
            ResourcesManager.LogPlayerIn(level, Client);
            level.Tick();
            var loginOk = new LoginOkMessage(Client);
            var avatar  = level.GetPlayerAvatar();

            loginOk.SetAccountId(avatar.GetId());
            loginOk.SetPassToken(avatar.GetUserToken());
            loginOk.SetServerMajorVersion(MajorVersion);
            loginOk.SetServerBuild(MinorVersion);
            loginOk.SetContentVersion(ContentVersion);
            loginOk.SetServerEnvironment("prod");
            loginOk.SetDaysSinceStartedPlaying(0);
            loginOk.SetServerTime(Math.Round(level.GetTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds * 1000).ToString(CultureInfo.InvariantCulture));
            loginOk.SetAccountCreatedDate("1414003838000");
            loginOk.SetStartupCooldownSeconds(0);
            loginOk.SetCountryCode(avatar.GetUserRegion().ToUpper());
            PacketManager.ProcessOutgoingPacket(loginOk);
            var alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

            PacketManager.ProcessOutgoingPacket(new OwnHomeDataMessage(Client, level));

            if (alliance == null)
            {
                level.GetPlayerAvatar().SetAllianceId(0);
            }
            else
            {
                PacketManager.ProcessOutgoingPacket(new AllianceFullEntryMessage(Client, alliance));
                PacketManager.ProcessOutgoingPacket(new AllianceStreamMessage(Client, alliance));
            }
            PacketManager.ProcessOutgoingPacket(new BookmarkMessage(Client));
            PacketManager.ProcessOutgoingPacket(new LeaguePlayersMessage(Client));
        }
コード例 #2
0
        async void LogUser()
        {
            try
            {
                ResourcesManager.LogPlayerIn(level, Client);
                level.Tick();
                level.SetIPAddress(Client.CIPAddress);
                LoginOkMessage l      = new LoginOkMessage(Client);
                ClientAvatar   avatar = level.GetPlayerAvatar();
                l.SetAccountId(avatar.GetId());
                l.SetPassToken(avatar.GetUserToken());
                l.SetServerMajorVersion(MajorVersion);
                l.SetServerBuild(MinorVersion);
                l.SetContentVersion(ContentVersion);
                l.SetServerEnvironment("prod");
                l.SetDaysSinceStartedPlaying(0);
                l.SetServerTime(Math.Round(level.GetTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds * 1000).ToString(CultureInfo.InvariantCulture));
                l.SetAccountCreatedDate(avatar.GetAccountCreationDate().ToString());
                l.SetStartupCooldownSeconds(0);
                l.SetCountryCode(avatar.GetUserRegion().ToUpper());
                PacketProcessor.Send(l);

                Alliance alliance = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

                if (ResourcesManager.IsPlayerOnline(level))
                {
                    AllianceMailStreamEntry mail = new AllianceMailStreamEntry();
                    mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                    mail.SetSenderId(0);
                    mail.SetSenderAvatarId(0);
                    /*FOR FHX*/   //mail.SetSenderName("Clash Of Heroes Team");
                    mail.SetSenderName("Server Manager");
                    mail.SetIsNew(2);
                    mail.SetAllianceId(0);
                    mail.SetSenderLeagueId(22);
                    mail.SetAllianceBadgeData(1526735450);
                    /*FOR FHX*/   //mail.SetAllianceName("COH-TEAM");
                    mail.SetAllianceName("Server Admin");
                    mail.SetMessage(ConfigurationManager.AppSettings["AdminMessage"]);
                    mail.SetSenderLevel(500);
                    AvatarStreamEntryMessage p = new AvatarStreamEntryMessage(level.GetClient());
                    p.SetAvatarStreamEntry(mail);
                    PacketProcessor.Send(p);
                }

                if (alliance != null)
                {
                    PacketProcessor.Send(new AllianceFullEntryMessage(Client, alliance));
                    PacketProcessor.Send(new AllianceStreamMessage(Client, alliance));
                    PacketProcessor.Send(new AllianceWarHistoryMessage(Client, alliance));
                }
                PacketProcessor.Send(new AvatarStreamMessage(Client));
                PacketProcessor.Send(new OwnHomeDataMessage(Client, level));
                PacketProcessor.Send(new BookmarkMessage(Client));
            } catch (Exception) { }
        }
コード例 #3
0
        private void LogUser()
        {
            ResourcesManager.LogPlayerIn(level, Client);
            level.Tick();

            var loginOk = new LoginOkMessage(Client);
            var avatar  = level.GetPlayerAvatar();

            loginOk.SetAccountId(avatar.GetId());
            loginOk.SetPassToken(avatar.GetUserToken());
            loginOk.SetServerMajorVersion(MajorVersion);
            loginOk.SetServerBuild(MinorVersion);
            loginOk.SetContentVersion(ContentVersion);
            loginOk.SetServerEnvironment("prod");
            loginOk.SetDaysSinceStartedPlaying(0);
            loginOk.SetServerTime(Math.Round(level.GetTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds * 1000).ToString(CultureInfo.InvariantCulture));
            loginOk.SetAccountCreatedDate(avatar.GetAccountCreationDate().ToString());
            loginOk.SetStartupCooldownSeconds(0);
            loginOk.SetCountryCode(avatar.GetUserRegion() ?? "EN");
            loginOk.Send();

            var alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

            if (ResourcesManager.IsPlayerOnline(level))
            {
                var mail = new AllianceMailStreamEntry();
                mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                mail.SetSenderId(0);
                mail.SetSenderAvatarId(0);
                mail.SetSenderName("Clash of Magic Admin");
                mail.SetIsNew(2);
                mail.SetAllianceId(0);
                mail.SetSenderLeagueId(22);
                mail.SetAllianceBadgeData(1526735450);
                mail.SetAllianceName("Clash of Magic Admin");
                mail.SetMessage(ConfigurationManager.AppSettings["AdminMessage"]);
                mail.SetSenderLevel(500);
                var p = new AvatarStreamEntryMessage(level.GetClient());
                p.SetAvatarStreamEntry(mail);
                p.Send();
            }

            new OwnHomeDataMessage(Client, level).Send(); // THIS MESSAGE MUST BE SENT FIRST !!!
            new AvatarStreamMessage(Client).Send();

            if (alliance != null)
            {
                new AllianceFullEntryMessage(Client, alliance).Send();
                new AllianceStreamMessage(Client, alliance).Send();
                new AllianceWarHistoryMessage(Client, alliance).Send();
                //PacketManager.ProcessOutgoingPacket (new AllianceWarMapDataMessage(Client)); //Don't activate it (not done!)
            }

            new BookmarkMessage(Client).Send();
        }
コード例 #4
0
        void LogUser()
        {
            ResourcesManager.LogPlayerIn(level, Client);
            level.Tick();
            var loginOk = new LoginOkMessage(Client);
            var avatar  = level.GetPlayerAvatar();

            loginOk.SetAccountId(avatar.GetId());
            loginOk.SetPassToken(avatar.GetUserToken());
            loginOk.SetServerMajorVersion(MajorVersion);
            loginOk.SetServerBuild(MinorVersion);
            loginOk.SetContentVersion(ContentVersion);
            loginOk.SetServerEnvironment("prod");
            loginOk.SetDaysSinceStartedPlaying(0);
            loginOk.SetServerTime(Math.Round(level.GetTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds * 1000).ToString(CultureInfo.InvariantCulture));
            loginOk.SetAccountCreatedDate("1414003838000");
            loginOk.SetStartupCooldownSeconds(0);
            loginOk.SetCountryCode(avatar.GetUserRegion().ToUpper());
            PacketManager.ProcessOutgoingPacket(loginOk);
            PacketManager.ProcessOutgoingPacket(new OwnHomeDataMessage(Client, level));
            var alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

            if (ResourcesManager.IsPlayerOnline(level))
            {
                var mail = new AllianceMailStreamEntry();
                mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                mail.SetSenderId(0);
                mail.SetSenderAvatarId(0);
                mail.SetSenderName("Server Manager");
                mail.SetIsNew(0);
                mail.SetAllianceId(0);
                mail.SetSenderLeagueId(22);
                mail.SetAllianceBadgeData(1728059989);
                mail.SetAllianceName("Server Admin");
                mail.SetMessage(ConfigurationManager.AppSettings["AdminMessage"]);
                mail.SetSenderLevel(500);
                var p = new AvatarStreamEntryMessage(level.GetClient());
                p.SetAvatarStreamEntry(mail);
                PacketManager.ProcessOutgoingPacket(p);
            }

            if (alliance != null)
            {
                PacketManager.ProcessOutgoingPacket(new AllianceFullEntryMessage(Client, alliance));
                PacketManager.ProcessOutgoingPacket(new AllianceStreamMessage(Client, alliance));
                PacketManager.ProcessOutgoingPacket(new AllianceWarHistoryMessage(Client));
            }
            PacketManager.ProcessOutgoingPacket(new BookmarkMessage(Client));
        }
コード例 #5
0
        private async void LoginMessageReceived(LoginMessage message)
        {
            if (this.m_connection.State == ClientConnectionState.DEFAULT &&
                this.CheckClientVersion(message.GetClientMajorVersion(), message.GetClientBuildVersion(), message.GetAppVersion(), message.GetResourceSha(), message.IsAndroidClient()) &&
                this.CheckServerCapabilities())
            {
                this.m_connection.Messaging.SetScramblerSeed(message.GetScramblerSeed());
                this.m_connection.SetState(ClientConnectionState.LOGIN);

                AccountDocument accountDocument;

                if (message.GetAccountId().IsZero() && message.GetPassToken() == null)
                {
                    IOperationResult <ulong> incrementSeedResult = await ServerProxy.AccountDatabase.IncrementSeed();

                    if (!incrementSeedResult.Success)
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.SERVER_MAINTENANCE);
                        loginFailedMessage.SetReason("Internal server error");
                        this.SendMessage(loginFailedMessage);
                        return;
                    }

                    accountDocument = new AccountDocument((long)incrementSeedResult.Value);
                    accountDocument.Init();
                    accountDocument.Country = this.m_connection.Location;

                    IOperationResult <string> createAccountResult = await ServerProxy.AccountDatabase.Insert((long)incrementSeedResult.Value, CouchbaseDocument.Save(accountDocument));

                    if (!createAccountResult.Success)
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.SERVER_MAINTENANCE);
                        loginFailedMessage.SetReason("Internal server error");
                        this.SendMessage(loginFailedMessage);
                        return;
                    }
                }
                else
                {
                    IOperationResult <string> getResult = await ServerProxy.AccountDatabase.Get(message.GetAccountId());

                    if (!getResult.Success)
                    {
                        if (getResult.Status == ResponseStatus.KeyNotFound)
                        {
                            LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                            loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.ACCOUNT_NOT_EXISTS);
                            this.SendMessage(loginFailedMessage);
                        }
                        else
                        {
                            LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                            loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.SERVER_MAINTENANCE);
                            loginFailedMessage.SetReason("Internal server error");
                            this.SendMessage(loginFailedMessage);
                        }

                        return;
                    }

                    accountDocument = CouchbaseDocument.Load <AccountDocument>(getResult.Value);

                    if (accountDocument.PassToken != message.GetPassToken())
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.ACCOUNT_NOT_EXISTS);
                        this.SendMessage(loginFailedMessage);
                        return;
                    }
                }

                if (accountDocument.State != AccountState.NORMAL)
                {
                    switch (accountDocument.State)
                    {
                    case AccountState.BANNED:
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.BANNED);
                        loginFailedMessage.SetReason(accountDocument.StateArg);
                        this.SendMessage(loginFailedMessage);
                        return;
                    }

                    case AccountState.LOCKED:
                    {
                        LoginFailedMessage loginFailedMessage = new LoginFailedMessage();
                        loginFailedMessage.SetErrorCode(LoginFailedMessage.ErrorCode.ACCOUNT_LOCKED);
                        this.SendMessage(loginFailedMessage);
                        return;
                    }
                    }
                }

                ProxySession session     = ProxySessionManager.Create(this.m_connection, accountDocument);
                RedisValue   prevSession = await ServerProxy.SessionDatabase.GetSet(accountDocument.Id, session.Id.ToString());

                if (!prevSession.IsNull)
                {
                    long prevSessionId = long.Parse(prevSession);

                    ServerMessageManager.SendMessage(new StopSessionMessage
                    {
                        Reason    = 1,
                        SessionId = prevSessionId
                    }, ServerManager.GetProxySocket(prevSessionId));
                }

                session.SetSocket(ServerCore.Socket); // Proxy

                LoginOkMessage loginOkMessage = new LoginOkMessage();

                loginOkMessage.SetAccountId(accountDocument.Id);
                loginOkMessage.SetHomeId(accountDocument.Id);
                loginOkMessage.SetPassToken(accountDocument.PassToken);
                loginOkMessage.SetFacebookId(accountDocument.FacebookId);
                loginOkMessage.SetGamecenterId(accountDocument.GamecenterId);

                loginOkMessage.SetServerMajorVersion(LogicVersion.MAJOR_VERSION);
                loginOkMessage.SetServerBuildVersion(LogicVersion.BUILD_VERSION);
                loginOkMessage.SetContentVersion(ResourceManager.GetContentVersion());
                loginOkMessage.SetServerEnvironment(EnvironmentSettings.Environment);
                loginOkMessage.SetSessionCount(accountDocument.SessionCount);
                loginOkMessage.SetPlayTimeSeconds(accountDocument.PlayTimeSeconds);
                loginOkMessage.SetAccountCreatedDate(accountDocument.CreateTime.ToString());
                loginOkMessage.SetStartupCooldownSeconds(ServerProxy.GetStartupCooldownSeconds());
                loginOkMessage.SetRegion(this.m_connection.Location);

                loginOkMessage.SetFacebookAppId(ResourceSettings.FacebookAppId);
                loginOkMessage.SetGoogleServiceId(ResourceSettings.GoogleServiceId);

                loginOkMessage.SetContentUrlList(ResourceSettings.ContentUrlList);
                loginOkMessage.SetChronosContentUrlList(ResourceSettings.ChronosContentUrlList);

                this.SendMessage(loginOkMessage);
                this.m_connection.SetSession(session);
                this.m_connection.SetState(ClientConnectionState.LOGGED);

                if (this.m_connection.State == ClientConnectionState.LOGGED)
                {
                    accountDocument.SessionCount   += 1;
                    accountDocument.LastSessionTime = TimeUtil.GetTimestamp();

                    ServerRequestManager.Create(new BindServerSocketRequestMessage
                    {
                        ServerType = 9,
                        ServerId   = ServerManager.GetDocumentSocket(9, accountDocument.Id).ServerId,
                        SessionId  = session.Id
                    }, ServerCore.Socket, 5).OnComplete = this.OnGameServerBound;

                    await ServerProxy.AccountDatabase.Update(accountDocument.Id, CouchbaseDocument.Save(accountDocument));
                }
                else
                {
                    this.m_connection.DestructSession();
                }
            }
        }