public override async void Process()
        {
            var info = Device.Player.Home.AllianceInfo;

            if (!info.HasAlliance)
            {
                return;
            }

            var alliance = await Resources.Alliances.GetAllianceAsync(info.Id);

            if (alliance == null)
            {
                return;
            }

            var entry = new ChatStreamEntry
            {
                Message = Message
            };

            entry.SetSender(Device.Player);

            alliance.AddEntry(entry);
        }
Ejemplo n.º 2
0
        public override async Task Process()
        {
            var alliance = await Resources.AllianceCache.GetAlliance(Device.Player.AllianceId);

            if (alliance != null)
            {
                var entry = new ChatStreamEntry
                {
                    CreationDateTime = DateTime.Now,
                    Id         = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds,
                    Message    = Message,
                    SenderRole = alliance.GetRole(Device.Player.AccountId)
                };

                entry.SetSender(Device.Player);

                alliance.AddEntry(entry);

                foreach (var member in alliance.Members)
                {
                    var player = await Resources.PlayerCache.GetPlayer(member.AccountId, true);

                    if (player != null)
                    {
                        await Resources.Gateway.Send(new AllianceStreamEntryMessage(player.Device)
                        {
                            AllianceStreamEntry = entry
                        });
                    }
                }
            }
        }
        public void OnChatToAllianceStreamMessageReceived(ChatToAllianceStreamMessage message)
        {
            if (!this.CanSendGlobalChatMessage())
            {
                return;
            }

            if (this.m_session.Alliance != null)
            {
                string chatMessage = message.RemoveMessage();

                if (string.IsNullOrEmpty(chatMessage))
                {
                    return;
                }
                if (chatMessage.Length > 128)
                {
                    chatMessage = chatMessage.Substring(0, 128);
                }

                AllianceMemberEntry memberEntry     = this.m_session.Alliance.Members[this.m_session.AccountId];
                ChatStreamEntry     chatStreamEntry = new ChatStreamEntry();
                AllianceStreamEntryUtil.SetSenderInfo(chatStreamEntry, memberEntry);

                chatStreamEntry.SetMessage(WordCensorUtil.FilterMessage(chatMessage));

                StreamManager.Create(this.m_session.Alliance.Id, chatStreamEntry);
                this.m_session.Alliance.AddStreamEntry(chatStreamEntry);
                AllianceManager.Save(this.m_session.Alliance);
            }
        }
Ejemplo n.º 4
0
        public override void Process(Level level)
        {
            var avatar     = level.GetPlayerAvatar();
            var allianceId = avatar.GetAllianceId();

            if (allianceId > 0)
            {
                ChatStreamEntry cm = new ChatStreamEntry();
                cm.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                cm.SetAvatar(avatar);
                cm.SetMessage(m_vChatMessage);

                Alliance alliance = ObjectManager.GetAlliance(allianceId);
                if (alliance != null)
                {
                    alliance.AddChatMessage(cm);

                    foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                    {
                        if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == allianceId)
                        {
                            var p = new AllianceStreamEntryMessage(onlinePlayer.GetClient());
                            p.SetStreamEntry(cm);
                            PacketManager.ProcessOutgoingPacket(p);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public override void Process(Level level)
        {
            var avatar     = level.GetPlayerAvatar();
            var allianceId = avatar.GetAllianceId();

            if (allianceId > 0)
            {
                if (m_vChatMessage.Length > 0)
                {
                    if (m_vChatMessage[0] == '/')
                    {
                        var obj = GameOpCommandFactory.Parse(m_vChatMessage);
                        if (obj != null)
                        {
                            var player = "";
                            if (level != null)
                            {
                                player += " (" + avatar.GetId() + ", " + avatar.GetAvatarName() + ")";
                            }
                            Debugger.WriteLine("\t" + obj.GetType().Name + player);
                            ((GameOpCommand)obj).Execute(level);
                        }
                    }
                    else if (!m_vChatMessage.Contains("./"))
                    {
                        var cm = new ChatStreamEntry();
                        cm.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                        cm.SetAvatar(avatar);
                        cm.SetMessage(FilterString(m_vChatMessage));

                        var alliance = ObjectManager.GetAlliance(allianceId);
                        if (alliance != null)
                        {
                            alliance.AddChatMessage(cm);

                            foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                            {
                                if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == allianceId)
                                {
                                    var p    = new AllianceStreamEntryMessage(onlinePlayer.GetClient());
                                    var name = cm.GetSenderName();
                                    if (onlinePlayer.isPermittedUser())
                                    {
                                        cm.SetSenderName(name + " #" + cm.GetSenderId());
                                    }

                                    p.SetStreamEntry(cm);
                                    PacketManager.ProcessOutgoingPacket(p);

                                    if (onlinePlayer.isPermittedUser())
                                    {
                                        cm.SetSenderName(name);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public override async void Process(Level level)
        {
            try {
                if (m_vChatMessage.Length > 0)
                {
                    if (m_vChatMessage.Length < 101)
                    {
                        if (m_vChatMessage[0] == '/')
                        {
                            Object obj = GameOpCommandFactory.Parse(m_vChatMessage);
                            if (obj != null)
                            {
                                string player = "";
                                if (level != null)
                                {
                                    player += " (" + level.GetPlayerAvatar().GetId() + ", " +
                                              level.GetPlayerAvatar().GetAvatarName() + ")";
                                }
                                ((GameOpCommand)obj).Execute(level);
                            }
                        }
                        else
                        {
                            ClientAvatar avatar     = level.GetPlayerAvatar();
                            long         allianceId = avatar.GetAllianceId();
                            if (allianceId > 0)
                            {
                                ChatStreamEntry cm = new ChatStreamEntry();
                                cm.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                                cm.SetSender(avatar);
                                cm.SetMessage(m_vChatMessage);

                                Alliance alliance = await ObjectManager.GetAlliance(allianceId);

                                if (alliance != null)
                                {
                                    alliance.AddChatMessage(cm);

                                    foreach (var op in alliance.GetAllianceMembers())
                                    {
                                        Level player = await ResourcesManager.GetPlayer(op.GetAvatarId());

                                        if (player.GetClient() != null)
                                        {
                                            AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(player.GetClient());
                                            p.SetStreamEntry(cm);
                                            PacketProcessor.Send(p);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (Exception) { }
        }
        internal override async void Process()
        {
            try {
                if (m_vChatMessage.Length > 0)
                {
                    if (m_vChatMessage.Length < 101)
                    {
                        if (m_vChatMessage[0] == '/')
                        {
                            Object obj = GameOpCommandFactory.Parse(m_vChatMessage);
                            if (obj != null)
                            {
                                string player = "";
                                if (this.Device.Player != null)
                                {
                                    player += " (" + this.Device.Player.Avatar.UserId + ", " +
                                              this.Device.Player.Avatar.AvatarName + ")";
                                }
                                ((GameOpCommand)obj).Execute(this.Device.Player);
                            }
                        }
                        else
                        {
                            ClientAvatar avatar     = this.Device.Player.Avatar;
                            long         allianceId = avatar.AllianceId;
                            if (allianceId > 0)
                            {
                                ChatStreamEntry cm = new ChatStreamEntry();
                                cm.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                                cm.SetSender(avatar);
                                cm.Message = m_vChatMessage;

                                Alliance alliance = ObjectManager.GetAlliance(allianceId);
                                if (alliance != null)
                                {
                                    alliance.AddChatMessage(cm);

                                    foreach (var op in alliance.GetAllianceMembers())
                                    {
                                        Level player = await ResourcesManager.GetPlayer(op.AvatarId);

                                        if (player.Client != null)
                                        {
                                            new AllianceStreamEntryMessage(player.Client)
                                            {
                                                StreamEntry = cm
                                            }.Send();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (Exception) { }
        }
        public override void Process(Level level)
        {
            if (m_vChatMessage.Length > 0)
            {
                if (m_vChatMessage[0] == '/')
                {
                    var obj = GameOpCommandFactory.Parse(m_vChatMessage);
                    if (obj != null)
                    {
                        var player = "";
                        if (level != null)
                        {
                            player += " (" + level.GetPlayerAvatar().GetId() + ", " +
                                      level.GetPlayerAvatar().GetAvatarName() + ")";
                        }
                        ((GameOpCommand)obj).Execute(level);
                    }
                }
                else
                {
                    var avatar     = level.GetPlayerAvatar();
                    var allianceId = avatar.GetAllianceId();
                    if (allianceId > 0)
                    {
                        var cm = new ChatStreamEntry();
                        cm.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                        cm.SetSender(avatar);
                        cm.SetMessage(m_vChatMessage);

                        var alliance = ObjectManager.GetAlliance(allianceId);
                        if (alliance != null)
                        {
                            alliance.AddChatMessage(cm);

                            Parallel.ForEach((alliance.GetAllianceMembers()), op =>
                            {
                                Level player = ResourcesManager.GetPlayer(op.GetAvatarId());
                                if (player.GetClient() != null)
                                {
                                    var p = new AllianceStreamEntryMessage(player.GetClient());
                                    p.SetStreamEntry(cm);
                                    p.Send();
                                }
                            });
                        }
                    }
                }
            }
        }
        public override void Process(Level level)
        {
            //Clans Edit Manager
            var alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

            if (alliance != null)
            {
                alliance.SetAllianceDescription(m_vAllianceDescription);
                alliance.SetAllianceBadgeData(m_vAllianceBadgeData);
                alliance.SetAllianceType(m_vAllianceType);
                alliance.SetRequiredScore(m_vRequiredScore);
                alliance.SetWarFrequency(m_vWarFrequency);
                alliance.SetAllianceOrigin(m_vAllianceOrigin);

                var avatar     = level.GetPlayerAvatar();
                var allianceId = avatar.GetAllianceId();
                if (allianceId > 0)
                {
                    var cm = new ChatStreamEntry();
                    cm.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                    cm.SetSenderId(0);
                    cm.SetHomeId(0);
                    cm.SetSenderLeagueId(22);
                    cm.SetSenderName("System Manager");
                    cm.SetSenderRole(2);
                    cm.SetMessage("Clan settings updated!");

                    var alliance1 = ObjectManager.GetAlliance(allianceId);
                    if (alliance != null)
                    {
                        alliance1.AddChatMessage(cm);

                        foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                        {
                            if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == allianceId)
                            {
                                var p = new AllianceStreamEntryMessage(onlinePlayer.GetClient());
                                p.SetStreamEntry(cm);
                                PacketManager.ProcessOutgoingPacket(p);
                                PacketManager.ProcessOutgoingPacket(new OwnHomeDataMessage(Client, level));
                                PacketManager.ProcessOutgoingPacket(new AllianceDataMessage(Client, alliance));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public override async void Process()
        {
            var info = Device.Player.Home.AllianceInfo;

            if (!info.HasAlliance)
            {
                return;
            }

            var alliance = await Resources.Alliances.GetAllianceAsync(info.Id);

            if (alliance == null)
            {
                return;
            }

            if (Message.StartsWith('/'))
            {
                var cmd      = Message.Split(' ');
                var cmdType  = cmd[0];
                var cmdValue = 0;

                if (cmd.Length > 1)
                {
                    if (Message.Split(' ')[1].Any(char.IsDigit))
                    {
                        int.TryParse(Message.Split(' ')[1], out cmdValue);
                    }
                }

                switch (cmdType)
                {
                case "/upgrade":
                {
                    Device.Player.Home.Deck.UpgradeAll();
                    Device.Disconnect();
                    break;
                }

                case "/exp":
                {
                    Device.Player.Home.AddExpPoints(cmdValue);
                    Device.Disconnect();
                    break;
                }

                case "/gold":
                {
                    Device.Player.Home.Gold += cmdValue;
                    Device.Disconnect();
                    break;
                }

                case "/status":
                {
                    await new ServerErrorMessage(Device)
                    {
                        Message = $"Online Players: {Resources.Players.Count}\nTotal Players: {await PlayerDb.CountAsync()}"
                    }.SendAsync();

                    break;
                }

                    /*case "/replay":
                     * {
                     *  await new HomeBattleReplayDataMessage(Device).SendAsync();
                     *  break;
                     * }
                     *
                     * case "/free":
                     * {
                     *  Device.Player.Home.FreeChestTime = Device.Player.Home.FreeChestTime.Subtract(TimeSpan.FromMinutes(245));
                     *  Device.Disconnect();
                     *  break;
                     * }*/

                    /*case "/trophies":
                     * {
                     *  if (cmdValue >= 0)
                     *      Device.Player.Home.Arena.AddTrophies(cmdValue);
                     *  else if (cmdValue < 0)
                     *      Device.Player.Home.Arena.RemoveTrophies(cmdValue);
                     *
                     *  Device.Disconnect();
                     *  break;
                     * }*/

                    /*case "/test":
                     * {
                     *  var entry = new DonateStreamEntry
                     *  {
                     *      Message = Message,
                     *      TotalCapacity = 10
                     *  };
                     *
                     *  entry.SetSender(Device.Player);
                     *
                     *  alliance.AddEntry(entry);
                     *
                     *  break;
                     * }*/

                    /*case "/test":
                     * {
                     *  var entry = new AllianceMailAvatarStreamEntry
                     *  {
                     *      Message = "Works",
                     *      Title = "Hehe",
                     *      AllianceId = 1,
                     *      AllianceName = "LOL",
                     *      AllianceBadge = 5,
                     *      IsNew = true
                     *  };
                     *
                     *  entry.SetSender(Device.Player);
                     *
                     *  Device.Player.AddEntry(entry);
                     *
                     *  break;
                     * }*/
                }
            }
            else
            {
                var entry = new ChatStreamEntry
                {
                    Message = Message
                };

                entry.SetSender(Device.Player);

                alliance.AddEntry(entry);
            }
        }
        public override async void Process()
        {
            var info = Device.Player.Home.AllianceInfo;

            if (!info.HasAlliance)
            {
                return;
            }

            var alliance = await Resources.Alliances.GetAllianceAsync(info.Id);

            if (alliance == null)
            {
                return;
            }

            if (Message.StartsWith('/'))
            {
                var cmd      = Message.Split(' ');
                var cmdType  = cmd[0];
                var cmdValue = 0;

                if (cmd.Length > 1)
                {
                    if (Message.Split(' ')[1].Any(char.IsDigit))
                    {
                        int.TryParse(Message.Split(' ')[1], out cmdValue);
                    }
                }

                switch (cmdType)
                {
                case "/max":
                {
                    var deck = Device.Player.Home.Deck;

                    foreach (var card in Cards.GetAllCards())
                    {
                        deck.Add(card);

                        for (var i = 0; i < 12; i++)
                        {
                            deck.UpgradeCard(card.ClassId, card.InstanceId, true);
                        }
                    }

                    await new ServerErrorMessage(Device)
                    {
                        Message = "Added all cards with max level"
                    }.SendAsync();

                    break;
                }

                case "/unlock":
                {
                    var deck = Device.Player.Home.Deck;

                    foreach (var card in Cards.GetAllCards())
                    {
                        deck.Add(card);
                    }

                    await new ServerErrorMessage(Device)
                    {
                        Message = "Added all cards"
                    }.SendAsync();

                    break;
                }

                case "/gold":
                {
                    Device.Player.Home.Gold += cmdValue;
                    Device.Disconnect();
                    break;
                }

                case "/gems":
                {
                    Device.Player.Home.Diamonds += cmdValue;
                    Device.Disconnect();
                    break;
                }

                case "/status":
                {
                    var entry = new ChatStreamEntry
                    {
                        Message =
                            $"Server status:\nBuild version: 1.5 (for 1.9.2)\nFingerprint SHA:\n{Resources.Fingerprint.Sha}\nOnline Players: {Resources.Players.Count}\nTotal Players: {await PlayerDb.CountAsync()}\n1v1 Battles: {Resources.Battles.Count}\n2v2 Battles: {Resources.DuoBattles.Count}\nTotal Clans: {await AllianceDb.CountAsync()}\nUptime: {DateTime.UtcNow.Subtract(Resources.StartTime).ToReadableString()}\nUsed RAM: {System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024) + " MB"}"
                    };

                    entry.SetSender(Device.Player);

                    alliance.AddEntry(entry);
                    break;
                }

                case "/free":
                {
                    Device.Player.Home.FreeChestTime = Device.Player.Home.FreeChestTime.Subtract(TimeSpan.FromMinutes(245));
                    Device.Disconnect();
                    break;
                }

                /*case "/replay":
                 * {
                 *  await new HomeBattleReplayDataMessage(Device).SendAsync();
                 *  break;
                 * }*/

                case "/trophies":
                {
                    if (cmdValue >= 0)
                    {
                        Device.Player.Home.Arena.AddTrophies(cmdValue);
                    }
                    else if (cmdValue < 0)
                    {
                        Device.Player.Home.Arena.RemoveTrophies(cmdValue);
                    }

                    Device.Disconnect();
                    break;
                }

                case "/set":
                {
                    Device.Player.Home.Arena.SetTrophies(cmdValue);

                    Device.Disconnect();
                    break;
                }

                case "/help":
                {
                    var help = new ChatStreamEntry
                    {
                        Message =
                            $"List of commands:\n/max - open all cards max. level\n/unlock - open all cards\n/gold x - give out gold, where x - amount of gold\n/ gems x - give out gems, where x - amount of gems\n/ status - a command that shows the server status (needed for admins)\n / free - resets the timer of the free chest\n/trophies x - adds trophies, where x - the number of trophies (can be negative)\n/ set x - the specified number of trophies is available, where x - the number of trophies"
                    };

                    help.SetSender(Device.Player);

                    alliance.AddEntry(help);
                    break;
                }

                default:
                    var error = new ChatStreamEntry
                    {
                        Message =
                            $"Command not found. Use /help for the list of commands."
                    };

                    error.SetSender(Device.Player);

                    alliance.AddEntry(error);
                    break;
                }
            }
            else
            {
                var entry = new ChatStreamEntry
                {
                    Message = Message
                };

                entry.SetSender(Device.Player);

                alliance.AddEntry(entry);
            }
        }
        public override async void Process()
        {
            var info = Device.Player.Home.AllianceInfo;

            if (!info.HasAlliance)
            {
                return;
            }

            var alliance = await Resources.Alliances.GetAllianceAsync(info.Id);

            if (alliance == null)
            {
                return;
            }

            if (Message.StartsWith('/'))
            {
                var cmd      = Message.Split(' ');
                var cmdType  = cmd[0];
                var cmdValue = 0;

                if (cmd.Length > 1)
                {
                    if (Message.Split(' ')[1].Any(char.IsDigit))
                    {
                        int.TryParse(Message.Split(' ')[1], out cmdValue);
                    }
                }

                switch (cmdType)
                {
                case "/max":
                {
                    var deck = Device.Player.Home.Deck;

                    foreach (var card in Cards.GetAllCards())
                    {
                        deck.Add(card);

                        for (var i = 0; i < 12; i++)
                        {
                            deck.UpgradeCard(card.ClassId, card.InstanceId, true);
                        }
                    }

                    await new ServerErrorMessage(Device)
                    {
                        Message = "Added all cards with max level"
                    }.SendAsync();

                    break;
                }

                case "/unlock":
                {
                    var deck = Device.Player.Home.Deck;

                    foreach (var card in Cards.GetAllCards())
                    {
                        deck.Add(card);
                    }

                    await new ServerErrorMessage(Device)
                    {
                        Message = "Added all cards"
                    }.SendAsync();

                    break;
                }

                case "/gold":
                {
                    Device.Player.Home.Gold += cmdValue;
                    Device.Disconnect();
                    break;
                }

                case "/status":
                {
                    await new ServerErrorMessage(Device)
                    {
                        Message =
                            $"Online Players: {Resources.Players.Count}\nTotal Players: {await PlayerDb.CountAsync()}\n1v1 Battles: {Resources.Battles.Count}\n2v2 Battles: {Resources.DuoBattles.Count}\nTotal Clans: {await AllianceDb.CountAsync()}\nUptime: {DateTime.UtcNow.Subtract(Resources.StartTime).ToReadableString()}"
                    }.SendAsync();

                    break;
                }

                    /*case "/free":
                     * {
                     *  Device.Player.Home.FreeChestTime = Device.Player.Home.FreeChestTime.Subtract(TimeSpan.FromMinutes(245));
                     *  Device.Disconnect();
                     *  break;
                     * }*/

                    /*case "/replay":
                     * {
                     *  await new HomeBattleReplayDataMessage(Device).SendAsync();
                     *  break;
                     * }*/

                    /*case "/trophies":
                     * {
                     *  if (cmdValue >= 0)
                     *      Device.Player.Home.Arena.AddTrophies(cmdValue);
                     *  else if (cmdValue < 0)
                     *      Device.Player.Home.Arena.RemoveTrophies(cmdValue);
                     *
                     *  Device.Disconnect();
                     *  break;
                     * }*/
                }
            }
            else
            {
                var entry = new ChatStreamEntry
                {
                    Message = Message
                };

                entry.SetSender(Device.Player);

                alliance.AddEntry(entry);
            }
        }
Ejemplo n.º 13
0
        public override async void Process()
        {
            var info = Device.Player.Home.AllianceInfo;

            if (!info.HasAlliance)
            {
                return;
            }

            var alliance = await Resources.Alliances.GetAllianceAsync(info.Id);

            if (alliance == null)
            {
                return;
            }

            if (Message.StartsWith('/'))
            {
                var cmd      = Message.Split(' ');
                var cmdType  = cmd[0];
                var cmdValue = 0;

                if (cmd.Length > 1)
                {
                    if (Message.Split(' ')[1].Any(char.IsDigit))
                    {
                        int.TryParse(Message.Split(' ')[1], out cmdValue);
                    }
                }

                switch (cmdType)
                {
                case "/upgrade":
                {
                    Device.Player.Home.Deck.UpgradeAll();
                    Device.Disconnect();
                    break;
                }

                case "/exp":
                {
                    Device.Player.Home.AddExpPoints(cmdValue);
                    Device.Disconnect();
                    break;
                }

                case "/gold":
                {
                    Device.Player.Home.Gold += cmdValue;
                    Device.Disconnect();
                    break;
                }

                    /*case "/test":
                     * {
                     *  var entry = new DonateStreamEntry
                     *  {
                     *      Message = Message,
                     *      TotalCapacity = 10
                     *  };
                     *
                     *  entry.SetSender(Device.Player);
                     *
                     *  alliance.AddEntry(entry);
                     *
                     *  break;
                     * }*/
                }
            }
            else
            {
                var entry = new ChatStreamEntry
                {
                    Message = Message
                };

                entry.SetSender(Device.Player);

                alliance.AddEntry(entry);
            }
        }