Beispiel #1
0
        public void StartClearing()
        {
            int constructionTime = GetObstacleData().ClearTimeSeconds;

            if (constructionTime < 1)
            {
                ClearingFinished();
            }
            else
            {
                m_vTimer = new Timer();
                m_vTimer.StartTimer(constructionTime, m_vLevel.GetTime());
                m_vLevel.WorkerManager.AllocateWorker(this);
            }
        }
Beispiel #2
0
 public ResourceProductionComponent(ConstructionItem ci, Level level) : base(ci)
 {
     this.m_vTimeSinceLastClick     = level.GetTime();
     this.m_vProductionResourceData = ObjectManager.DataTables.GetResourceByName(((BuildingData)ci.GetData()).ProducesResource);
     this.m_vResourcesPerHour       = ((BuildingData)ci.GetData()).ResourcePerHour;
     this.m_vMaxResources           = ((BuildingData)ci.GetData()).ResourceMax;
 }
 public void CreateAccount(Level l)
 {
     try
     {
         Debugger.WriteLine("Saving new account to database (player id: " + l.GetPlayerAvatar().GetId() + ")");
         using (var db = new Database.ucsdbEntities(m_vConnectionString))
         {
             db.player.Add(
                 new Database.player
                 {
                     PlayerId = l.GetPlayerAvatar().GetId(),
                     AccountStatus = l.GetAccountStatus(),
                     AccountPrivileges = l.GetAccountPrivileges(),
                     LastUpdateTime = l.GetTime(),
                     Avatar = l.GetPlayerAvatar().SaveToJSON(),
                     GameObjects = l.SaveToJSON()
                 }
             );
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debugger.WriteLine("An exception occured during CreateAccount processing:", ex);
     }
 }
Beispiel #4
0
 public ConstructionItem(Data data, Level level) : base(data, level)
 {
     m_vLevel          = level;
     IsBoosted         = false;
     m_vBoostEndTime   = level.GetTime();
     m_vIsConstructing = false;
     UpgradeLevel      = -1;
 }
 public ResourceProductionComponent(ConstructionItem ci, Level level)
     : base(ci)
 {
     this.m_vTimeSinceLastClick = level.GetTime();
     this.m_vProductionResourceData = ObjectManager.DataTables.GetResourceByName(((BuildingData)ci.GetData()).ProducesResource);
     this.m_vResourcesPerHour = ((BuildingData)ci.GetData()).ResourcePerHour;
     this.m_vMaxResources = ((BuildingData)ci.GetData()).ResourceMax;
 }
Beispiel #6
0
 public ObstacleManager(Level level)
 {
     m_vLevel = level;
     if (m_vObstacleLimit == -1)
     {
         m_vObstacleLimit          = CSVManager.DataTables.GetGlobals().GetGlobalData("OBSTACLE_COUNT_MAX").NumberValue;
         m_vObstacleRespawnSeconds =
             CSVManager.DataTables.GetGlobals().GetGlobalData("OBSTACLE_RESPAWN_SECONDS").NumberValue;
     }
     if (m_vSpawnAbleObstacles.Count() == 0)
     {
         var dt = CSVManager.DataTables.GetTable(7);
         for (var i = 0; i < dt.GetItemCount(); i++)
         {
             var od = (ObstacleData)dt.GetItemAt(i);
             if (!od.IsTombstone)
             {
                 if (!od.GetName().Contains("Gembox"))
                 {
                     if (od.RespawnWeight > 0)
                     {
                         m_vSpawnAbleObstacles.Add(od);
                         SumWeights += od.RespawnWeight;
                     }
                 }
                 else
                 {
                     m_vGemBoxes.Add(od);
                 }
             }
         }
     }
     m_vNormalTimer  = new Timer();
     m_vGemBoxTimer  = new Timer();
     m_vSpecialTimer = new Timer();
     m_vNormalTimer.StartTimer(m_vObstacleRespawnSeconds, level.GetTime());
     m_vGemBoxTimer.StartTimer(m_vObstacleRespawnSeconds * 2, level.GetTime());
     m_vSpecialTimer.StartTimer(m_vObstacleRespawnSeconds, level.GetTime());
     m_vObstacleClearCount = 0;
     m_vRespawnSeed        = new Random().Next();
 }
Beispiel #7
0
        public void Load(JObject jsonObject)
        {
            var jToken = jsonObject["respawnVars"];

            if (jToken != null)
            {
                var jObj = jToken.ToObject <JObject>();
                m_vRespawnSeed        = jObj["respawnSeed"].ToObject <int>();
                m_vObstacleClearCount = jObj["obstacleClearCounter"].ToObject <int>();
                if (jObj["normal_t"] != null)
                {
                    m_vNormalTimer.StartTimer(
                        m_vObstacleRespawnSeconds - jObj["secondsFromLastRespawn"].ToObject <int>(),
                        jObj["normal_t"].ToObject <DateTime>());
                    m_vGemBoxTimer.StartTimer(jObj["time_to_gembox_drop"].ToObject <int>(),
                                              jObj["gembox_t"].ToObject <DateTime>());
                    m_vSpecialTimer.StartTimer(jObj["time_to_special_drop"].ToObject <int>(),
                                               jObj["special_t"].ToObject <DateTime>());
                }
            }
            else
            {
                m_vNormalTimer.StartTimer(m_vObstacleRespawnSeconds, m_vLevel.GetTime());
                m_vGemBoxTimer.StartTimer(m_vObstacleRespawnSeconds * 2, m_vLevel.GetTime());
                m_vSpecialTimer.StartTimer(m_vObstacleRespawnSeconds, m_vLevel.GetTime());
            }
        }
Beispiel #8
0
        public override void Process(Level level)
        {
            if (!Convert.ToBoolean(ConfigurationManager.AppSettings["maintenanceMode"]) || Client.CState == 0)
            {
                var p = new LoginFailedMessage(Client);
                p.SetErrorCode(10);
                PacketManager.ProcessOutgoingPacket(p);
                return;
            }

            /*
            var versionData = ConfigurationManager.AppSettings["clientVersion"].Split('.');
            if (versionData.Length >= 2)
            {
                var cv = ClientVersion.Split('.');
                if (cv[0] != versionData[0] || cv[1] != versionData[1])
                {
                    var p = new LoginFailedMessage(Client);
                    p.SetErrorCode(8);
                    p.SetUpdateURL(Convert.ToString(ConfigurationManager.AppSettings["UpdateUrl"]));
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }
            }
            else
            {
                Debugger.WriteLine("[UCR][10101] Connection failed. UCR config key clientVersion is not properly set.");
            }
            */

            level = ResourcesManager.GetPlayer(UserID);
            if (level != null)
            {
                if (level.GetAccountStatus() == 99)
                {
                    var p = new LoginFailedMessage(Client);
                    p.SetErrorCode(11);
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }
            }
            else
            {
                level = ObjectManager.CreateAvatar(UserID);
                var tokenSeed = new byte[20];
                new Random().NextBytes(tokenSeed);
                using (SHA1 sha = new SHA1CryptoServiceProvider())
                    UserToken = BitConverter.ToString(sha.ComputeHash(tokenSeed)).Replace("-", string.Empty);
            }

            if (Convert.ToBoolean(ConfigurationManager.AppSettings["useCustomPatch"]))
                if (MasterHash != ObjectManager.FingerPrint.sha)
                {
                    var p = new LoginFailedMessage(Client);
                    p.SetErrorCode(7);
                    p.SetResourceFingerprintData(ObjectManager.FingerPrint.SaveToJson());
                    p.SetContentURL(ConfigurationManager.AppSettings["patchingServer"]);
                    p.SetUpdateURL("http://www.ultrapowa.com/client");
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }

            Client.ClientSeed = Unknown;
            ResourcesManager.LogPlayerIn(level, Client);
            level.Tick();

            var loginOk = new LoginOkMessage(Client);
            var avatar = level.GetPlayerAvatar();
            loginOk.SetAccountId(avatar.GetId());
            loginOk.SetPassToken(UserToken);
            loginOk.SetServerEnvironment("prod");
            loginOk.SetDaysSinceStartedPlaying(10);
            loginOk.SetServerTime(Math.Round(level.GetTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds * 1000).ToString());
            loginOk.SetAccountCreatedDate("1414003838000");
            loginOk.SetStartupCooldownSeconds(0);
            loginOk.SetCountryCode(Language);
            PacketManager.ProcessOutgoingPacket(loginOk);

            /*
            var alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());
            if (alliance == null)
                level.GetPlayerAvatar().SetAllianceId(0);

            PacketManager.ProcessOutgoingPacket(new OwnHomeDataMessage(Client, level));
            */
        }
Beispiel #9
0
 public int GetRemainingConstructionTime()
 {
     return(m_vTimer.GetRemainingSeconds(m_vLevel.GetTime()));
 }
Beispiel #10
0
 public int GetRemainingClearingTime()
 {
     return(m_vTimer.GetRemainingSeconds(m_vLevel.GetTime()));
 }
Beispiel #11
0
        public override void Process(Level level)
        {
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["maintenanceMode"]))
            {
                var p = new LoginFailedMessage(this.Client);
                p.SetErrorCode(10);
                PacketManager.ProcessOutgoingPacket(p);
                return;
            }

            string[] versionData = ConfigurationManager.AppSettings["clientVersion"].Split('.');
            if(versionData.Length >= 2)
            {
                if(m_vClientMajorVersion != Convert.ToInt32(versionData[0]) || m_vClientBuild != Convert.ToInt32(versionData[1]))
                {
                    var p = new LoginFailedMessage(this.Client);
                    p.SetErrorCode(8);
                    p.SetUpdateURL("http://www.ultrapowa.com/");
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }
            }
            else
            {
                Debugger.WriteLine("Connection failed. UCS config key clientVersion is not properly set.");
            }

            level = ResourcesManager.GetPlayer(m_vAccountId);
            if(level != null)
            {
                if(level.GetAccountStatus() == 99)
                {
                    var p = new LoginFailedMessage(this.Client);
                    p.SetErrorCode(11);
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }
            }

            if(Convert.ToBoolean(ConfigurationManager.AppSettings["useCustomPatch"]))
            {
                if (m_vResourceSha != ObjectManager.FingerPrint.sha)
                {
                    var p = new LoginFailedMessage(this.Client);
                    p.SetErrorCode(7);
                    p.SetResourceFingerprintData(ObjectManager.FingerPrint.SaveToJson());
                    p.SetContentURL(ConfigurationManager.AppSettings["patchingServer"]);
                    p.SetUpdateURL("http://www.ultrapowa.com/");
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }
            }

            this.Client.ClientSeed = m_vClientSeed;
            PacketManager.ProcessOutgoingPacket(new SessionKeyMessage(this.Client));
            Debugger.WriteLine("[D] Retrieve Player Data for player " + m_vAccountId);
            Console.ResetColor();
            //New player
            if (level == null)
            {
                level = ObjectManager.CreateAvatar(m_vAccountId);
                byte[] tokenSeed = new byte[20];
                new Random().NextBytes(tokenSeed);
                SHA1 sha = new SHA1CryptoServiceProvider();
                m_vPassToken = BitConverter.ToString(sha.ComputeHash(tokenSeed)).Replace("-","");
            }
            if (level.GetAccountPrivileges() > 0)
                level.GetPlayerAvatar().SetLeagueId(21);
            if (level.GetAccountPrivileges() > 4)
                level.GetPlayerAvatar().SetLeagueId(22);
            ResourcesManager.LogPlayerIn(level, this.Client);
            level.Tick();

            var loginOk = new LoginOkMessage(this.Client);
            var avatar = level.GetPlayerAvatar();
            loginOk.SetAccountId(avatar.GetId());
            loginOk.SetPassToken(m_vPassToken);
            loginOk.SetServerMajorVersion(m_vClientMajorVersion);
            loginOk.SetServerBuild(m_vClientBuild);
            loginOk.SetContentVersion(m_vClientContentVersion);

            loginOk.SetDaysSinceStartedPlaying(10);
            loginOk.SetServerTime(Math.Round((level.GetTime().Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000).ToString());
            loginOk.SetAccountCreatedDate("1414003838000");
            loginOk.SetStartupCooldownSeconds(0);
            loginOk.SetCountryCode("US");
            PacketManager.ProcessOutgoingPacket(loginOk);

            Alliance alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());
            if (alliance == null)
                level.GetPlayerAvatar().SetAllianceId(0);
            PacketManager.ProcessOutgoingPacket(new OwnHomeDataMessage(this.Client, level));
            if (alliance != null)
                PacketManager.ProcessOutgoingPacket(new AllianceStreamMessage(this.Client, alliance));
        }
        public override void Process(Level level)
        {
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["maintenanceMode"]))
            {
                var p = new LoginFailedMessage(this.Client);
                p.SetErrorCode(10);
                PacketManager.ProcessOutgoingPacket(p);
                return;
            }

            string[] versionData = ConfigurationManager.AppSettings["clientVersion"].Split('.');
            if(versionData.Length >= 2)
            {
                if(m_vClientMajorVersion != Convert.ToInt32(versionData[0]) || m_vClientBuild != Convert.ToInt32(versionData[1]))
                {
                    var p = new LoginFailedMessage(this.Client);
                    p.SetErrorCode(8);
                    p.SetUpdateURL("market://details?id=com.supercell.clashofclans");
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }
            }
            else
            {
                Debugger.WriteLine("Connection failed. UCS config key clientVersion is not properly set.");
            }

            level = ResourcesManager.GetPlayer(m_vAccountId);
            if(level != null)
            {
                if(level.GetAccountStatus() == 99)
                {
                    var p = new LoginFailedMessage(this.Client);
                    p.SetErrorCode(11);
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }
            }

            if(Convert.ToBoolean(ConfigurationManager.AppSettings["useCustomPatch"]))
            {
                if (m_vResourceSha != ObjectManager.FingerPrint.sha)
                {
                    var p = new LoginFailedMessage(this.Client);
                    p.SetErrorCode(7);
                    p.SetResourceFingerprintData(ObjectManager.FingerPrint.SaveToJson());
                    p.SetContentURL(ConfigurationManager.AppSettings["patchingServer"]);
                    p.SetUpdateURL("market://details?id=com.supercell.clashofclans");
                    PacketManager.ProcessOutgoingPacket(p);
                    return;
                }
            }

            this.Client.ClientSeed = m_vClientSeed;
            PacketManager.ProcessOutgoingPacket(new SessionKeyMessage(this.Client));
            //Console.WriteLine("Debug: Retrieve Player Data for player " + auth.PlayerId.ToString());
            //New player
            if (level == null)
            {
                level = ObjectManager.CreateAvatar(m_vAccountId);
                byte[] tokenSeed = new byte[20];
                new Random().NextBytes(tokenSeed);
                SHA1 sha = new SHA1CryptoServiceProvider();
                m_vPassToken = BitConverter.ToString(sha.ComputeHash(tokenSeed)).Replace("-","");
            }
            //if (level.GetAccountPrivileges() > 0)
            //    level.GetPlayerAvatar().SetLeagueId(21);
            //if (level.GetAccountPrivileges() > 4)
            //    level.GetPlayerAvatar().SetLeagueId(22);
            if (level.GetPlayerAvatar().GetScore() >= 400 && level.GetPlayerAvatar().GetScore() <= 800)
            {
                level.GetPlayerAvatar().SetLeagueId(3);
            }
            else if (level.GetPlayerAvatar().GetScore() >= 801 && level.GetPlayerAvatar().GetScore() <= 1400)
            {
                level.GetPlayerAvatar().SetLeagueId(6);
            }
            else if (level.GetPlayerAvatar().GetScore() >= 1401 && level.GetPlayerAvatar().GetScore() <= 2000)
            {
                level.GetPlayerAvatar().SetLeagueId(9);
            }
            else if (level.GetPlayerAvatar().GetScore() >= 2001 && level.GetPlayerAvatar().GetScore() <= 2600)
            {
                level.GetPlayerAvatar().SetLeagueId(12);
            }
            else if (level.GetPlayerAvatar().GetScore() >= 2601 && level.GetPlayerAvatar().GetScore() <= 3200)
            {
                level.GetPlayerAvatar().SetLeagueId(15);
            }
            else if (level.GetPlayerAvatar().GetScore() >= 3201 && level.GetPlayerAvatar().GetScore() <= 4099)
            {
                level.GetPlayerAvatar().SetLeagueId(18);
            }
            else if (level.GetPlayerAvatar().GetScore() >= 4100)
            {
                level.GetPlayerAvatar().SetLeagueId(21);
            }

            ResourcesManager.LogPlayerIn(level, this.Client);
            level.Tick();

            var loginOk = new LoginOkMessage(this.Client);
            var avatar = level.GetPlayerAvatar();
            loginOk.SetAccountId(avatar.GetId());
            loginOk.SetPassToken(m_vPassToken);
            loginOk.SetServerMajorVersion(m_vClientMajorVersion);
            loginOk.SetServerBuild(m_vClientBuild);
            loginOk.SetContentVersion(m_vClientContentVersion);
            loginOk.SetServerEnvironment("prod");
            loginOk.SetDaysSinceStartedPlaying(10);
            loginOk.SetServerTime(Math.Round((level.GetTime().Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000).ToString());
            loginOk.SetAccountCreatedDate("1414003838000");
            loginOk.SetStartupCooldownSeconds(0);
            loginOk.SetCountryCode("FR");
            PacketManager.ProcessOutgoingPacket(loginOk);

            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);
                mail.SetSenderName("EuroClash.Net");
                mail.SetIsNew(0);
                mail.SetAllianceId(0);
                mail.SetAllianceBadgeData(0);
                mail.SetAllianceName("Automatic Information");
                mail.SetMessage("Welcome to EuroClash ! \nTo see available commands type /help \n\nSaveGame is fully automatic, you don't have to type anything, commands like /savegame or ./savegame doesn't exist, all commands are available on /help\n\nTrophies are randomly given on first login, this will be fixed soon.\n\nNow Clans calculate trophies of players, 50% of their trophies will be added to clan trophies, still kinda bugged, we're testing with simple math. Clan Owner's trophies are not added (bug).\n\nServer is currently in Alpha, to see bugfixes please visit http://euroclash.net ChangeLog Section!");
                mail.SetSenderLeagueId(22);
                var abe = new AvatarStreamEntryMessage(level.GetClient());
                abe.SetAvatarStreamEntry(mail);
                PacketManager.ProcessOutgoingPacket(abe);
            }
            //level.GetPlayerAvatar().SetResourceCount(ObjectManager.DataTables.GetResourceByName("Diamonds"), Convert.ToInt32(1000000));

            Alliance alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());
            if (alliance == null)
                level.GetPlayerAvatar().SetAllianceId(0);
            PacketManager.ProcessOutgoingPacket(new OwnHomeDataMessage(this.Client, level));
            if (alliance != null)
                PacketManager.ProcessOutgoingPacket(new AllianceStreamMessage(this.Client, alliance));
        }