Пример #1
0
        internal override void Process()
        {
            if (this.Connection.Avatar.Rank >= this.RequiredRank)
            {
                if (this.Parameters.Length >= 2)
                {
                    try
                    {
                        if (Enum.TryParse(this.Parameters[1], out this.Rank))
                        {
                            if (this.Parameters[0] == this.Tag)
                            {
                                LogicLong         id     = LogicTagUtil.ToLogicLong(this.Tag);
                                LogicClientAvatar avatar = Avatars.Get(id);

                                if (this.Rank > this.Connection.Avatar.Rank)
                                {
                                    this.Connection.SendChatMessage("Target privileges are higher then yours.");
                                }
                                else
                                {
                                    if (avatar != null)
                                    {
                                        avatar.SetRank(this.Rank);
                                        this.Connection.SendChatMessage($"{avatar.Name} now has the rank {this.Rank}");
                                    }
                                    else
                                    {
                                        this.Help.AppendLine("Hashtags can only contain these characters:");
                                        this.Help.AppendLine("Numbers: 0, 2, 8, 9");
                                        this.Help.AppendLine("Letters: P, Y, L, Q, G, R, J, C, U, V");

                                        this.Connection.SendChatMessage(this.Help.ToString());
                                    }
                                }
                            }
                        }
                        else
                        {
                            this.Connection.SendChatMessage(this.Help.ToString());
                        }
                    }
                    catch (Exception exception)
                    {
                        this.Connection.SendChatMessage($"Failed with error {exception.Message}");
                    }
                }
                else
                {
                    this.Connection.SendChatMessage(this.Help.ToString());
                }
            }
            else
            {
                this.Connection.SendChatMessage("Insufficient privileges.");
            }
        }
Пример #2
0
        /// <summary>
        /// Adds the specified <see cref="StreamEntry"/>.
        /// </summary>
        internal void AddEntry(StreamEntry entry)
        {
            entry.LowID = this.Seed;

            if (this.Entries.Count >= 40)
            {
                this.Entries.RemoveAt(0);
            }

            this.Entries.Add(entry);

            foreach (LogicClientAvatar avatar in this.Members.Select(member => Avatars.Get(member.Identifier)).Where(avatar => avatar.Connection != null && avatar.Connection.IsConnected))
            {
                new AllianceStreamEntryMessage(avatar.Connection, entry).Send();
            }
        }
        internal override void Execute()
        {
            LogicClientAvatar avatar = Avatars.Get(this.Identifier);

            if (avatar != null)
            {
                Alliance alliance = avatar.Alliance;

                AllianceMember allianceMember = alliance.Members.Find(member => member.Identifier == this.Identifier);

                if (allianceMember != null)
                {
                    alliance.Members.Remove(allianceMember);
                }

                Alliances.Save(alliance);
            }
        }
Пример #4
0
        private static void FindNewLeader(Alliance alliance, AllianceMember member)
        {
            LogicClientAvatar avatar = Avatars.Get(member.Identifier);

            AllianceMember      newLeader = alliance.Members.Find(member => member.Role == (int)Alliance.Role.CoLeader);
            const Alliance.Role newRole   = Alliance.Role.Leader;

            if (newLeader != null)
            {
                newLeader.Role = (int)newRole;
            }
            else
            {
                newLeader = alliance.Members.Find(member => member.Role == (int)Alliance.Role.Admin);

                if (newLeader != null)
                {
                    newLeader.Role = (int)newRole;
                }
                else
                {
                    newLeader = alliance.Members[Loader.Random.Rand(alliance.Members.Count)];

                    if (newLeader != null)
                    {
                        newLeader.Role = (int)newRole;
                    }
                }
            }

            alliance.AddEntry(new StreamEntry(member, member, StreamEntry.StreamEvent.Demoted));
            alliance.AddEntry(new StreamEntry(newLeader, member, StreamEntry.StreamEvent.Promoted));

            avatar.Save();
            Avatars.Get(newLeader.Identifier).Save();

            new AvailableServerCommandMessage(avatar.Connection, new LogicChangeAllianceRoleCommand(avatar.Connection)
            {
                Role = newRole
            }).Send();
        }
Пример #5
0
        internal override void Handle()
        {
            // if (this.Trusted)
            {
                if (this.AvatarID.Low == 0)
                {
                    this.Connection.Avatar = Avatars.Create(this.Connection);

                    Debugger.Warning($"Player not found! Creating {this.Connection.Avatar.Identifier}...");

                    if (this.Connection.Avatar != null)
                    {
                        this.Login();
                    }
                    else
                    {
                        new LoginFailedMessage(this.Connection, Reason.Pause).Send();
                    }
                }
                else if (this.AvatarID.Low > 0)
                {
                    Debugger.Info($"{this.AvatarID} found! Logging in...");

                    this.Connection.Avatar = Avatars.Get(this.Connection, this.AvatarID);

                    if (this.Connection.Avatar == null)
                    {
                        Debugger.Warning("Account missing! Recreating...");
                        this.Connection.Avatar = Avatars.Create(this.Connection, this.AvatarID);
                    }

                    this.Login();
                }
                else
                {
                    Debugger.Error("Player tried to login with a player id inferior to 0.");
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Handles the request.
        /// </summary>
        private static void EndProcess(this HttpListenerContext context)
        {
            LogicLong player   = LogicTagUtil.ToLogicLong(context.Request.QueryString["player"]);
            int       debugCmd = LogicStringUtil.ConvertToInt(context.Request.QueryString["command"]);

            Connection connection = Avatars.Get(player).Connection;

            if (connection != null)
            {
                if (connection.IsConnected && LogicVersion.IsIntegration)
                {
                    new AvailableServerCommandMessage(connection, new LogicDebugCommand(connection, debugCmd)).Send();
                    context.Response.Close(LogicStringUtil.GetBytes("OK"), true);
                }
                else
                {
                    context.Response.Close(LogicStringUtil.GetBytes("Error: Connection.IsConnected == false or the server is not in integration mode"), true);
                }
            }
            else
            {
                context.Response.Close(LogicStringUtil.GetBytes("Error: Connection == null"), true);
            }
        }
        internal override void Handle()
        {
            if (this.Connection.Avatar.IsInAlliance)
            {
                Alliance alliance = Alliances.Get(this.Connection.Avatar.Alliance.Identifier);

                if (alliance != null)
                {
                    this.CheckValues(alliance);
                    Alliances.Save(alliance);

                    foreach (LogicClientAvatar avatar in alliance.Members.Select(member => Avatars.Get(member.Identifier)).Where(avatar => avatar.Connection != null))
                    {
                        new AvailableServerCommandMessage(avatar.Connection, new LogicAllianceSettingsChangedCommand(this.Connection)
                        {
                            Badge = this.BadgeData
                        }).Send();
                    }
                }
            }
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AvatarProfileMessage"/> class.
 /// </summary>
 internal AvatarProfileMessage(Connection connection, LogicLong visitId) : base(connection)
 {
     this.Type   = Message.AvatarProfile;
     this.Avatar = Avatars.Get(visitId);
 }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Parser"/> class.
        /// </summary>
        internal static void Init()
        {
            if (Parser.Initialized)
            {
                return;
            }

            new Thread(() =>
            {
                while (true)
                {
                    int cursorTop2 = Console.CursorTop = Console.WindowTop + Console.WindowHeight - 1;
                    Console.Write($"root@{Constants.LocalIP.ToString().Split(":")[0]} > ");

                    string[] command = Console.ReadLine()?.Split(' ');

                    Console.SetCursorPosition(0, cursorTop2 - 1);
                    Console.WriteLine(new string(' ', Console.BufferWidth));
                    Console.SetCursorPosition(0, cursorTop2 - 2);

                    switch (command?[0].Replace("/", string.Empty))
                    {
                    case "stats":
                        {
                            if (Loader.Initialized)
                            {
                                Console.WriteLine();
                                Console.WriteLine($"#  {DateTime.Now.ToString("d")} ---- STATS ---- {DateTime.Now.ToString("t")} #");
                                Console.WriteLine("# ----------------------------------- #");
                                Console.WriteLine($"# Connected Sockets # {LogicStringUtil.IntToString(Connections.Count).Pad(15)} #");
                                Console.WriteLine($"# In-Memory Avatars # {LogicStringUtil.IntToString(Avatars.Count).Pad(15)} #");
                                Console.WriteLine($"#  In-Memory Clans  # {LogicStringUtil.IntToString(Alliances.Count).Pad(15)} #");
                                Console.WriteLine("# ----------------------------------- #");
                            }

                            break;
                        }

                    case "setrank":
                        {
                            if (Loader.Initialized)
                            {
                                var tag  = command[1];
                                var rank = (Rank)Enum.GetValues(typeof(Rank)).GetValue(LogicStringUtil.ConvertToInt(command[2]));

                                LogicTagUtil.ToHighLow(tag, out int highId, out int lowId);

                                var player = Avatars.Get(new LogicLong(highId, lowId));
                                player.SetRank(rank);
                            }

                            break;
                        }

                    case "sendDebugCmd":
                        {
                            if (Loader.Initialized && LogicVersion.IsIntegration)
                            {
                                var commandId = LogicStringUtil.ConvertToInt(command[1]);

                                var playerId = command[2].Split('-');
                                var player   = Avatars.Get(new LogicLong(LogicStringUtil.ConvertToInt(playerId[0]), LogicStringUtil.ConvertToInt(playerId[1])));

                                new AvailableServerCommandMessage(player.Connection, new LogicDebugCommand(player.Connection, commandId)).Send(); // <- saving is false for the purpose of testing - this does not work yet
                                new OwnAvatarDataMessage(player.Connection).Send();

                                Console.WriteLine($"Sent Debug Command with ID {commandId} to player {player}");
                            }

                            break;
                        }

                    case "clear":
                        {
                            Console.Clear();
                            break;
                        }

                    case "exit":
                    case "shutdown":
                    case "stop":
                        {
                            EventsHandler.Exit();
                            break;
                        }

                    default:
                        {
                            Console.WriteLine();
                            break;
                        }
                    }
                }
            }).Start();

            Parser.Initialized = true;
        }