Exemplo n.º 1
0
        private void LottoZiehung()
        {
            LottoUserCollection lottoUsers = LottoUserCollection.Load();

            if (lottoUsers.Users.Count > 0)
            {
                server.SendServerMessage(String.Format("§{0}Drawing of the lotto numbers!", mc.Config.ResponseColorChar));

                LottoUserCollection listWinners = new LottoUserCollection();
                zahl = rnd.Next(config.Min, config.Max + 1);
                server.SendServerMessage(String.Format("§{0}The winning number is §6{1}", mc.Config.ResponseColorChar, zahl));
                foreach (LottoUser lottoUser in lottoUsers)
                {
                    User user = users.GetUserByName(lottoUser.Name);
                    if (!user.Generated)
                    {
                        if (lottoUser.Zahl == zahl)
                        {
                            listWinners.Add(lottoUser);
                        }
                    }
                }
                if (listWinners.Users.Count > 0)
                {
                    StringBuilder builder = new StringBuilder();
                    int           gewinn  = lottoUsers.Jackpot / listWinners.Users.Count;

                    foreach (LottoUser lottoUser in listWinners)
                    {
                        builder.AppendFormat("<{0}> ", lottoUser.Name);
                        User user = users.GetUserByName(lottoUser.Name);
                        if (!user.Generated)
                        {
                            user.Balance += gewinn;
                        }
                    }
                    if (listWinners.Users.Count == 1)
                    {
                        server.SendServerMessage(String.Format("§{0}The Player {1}had won the lottery! §6{2} {3}", mc.Config.ResponseColorChar, builder.ToString(), gewinn, mc.Config.CurrencySymbol));
                    }
                    else
                    {
                        server.SendServerMessage(String.Format("§{0}The Players {1}had won the lottery! §6{2} {3}", mc.Config.ResponseColorChar, builder.ToString(), gewinn, mc.Config.CurrencySymbol));
                    }
                    lottoUsers.Jackpot -= gewinn * listWinners.Users.Count;
                }
                else
                {
                    server.SendServerMessage(String.Format("§{0}No one has won the lottery!", mc.Config.ResponseColorChar));
                    lottoUsers.Jackpot += config.Bonus;
                }
                lottoUsers.Users.Clear();
                lottoUsers.Save();
            }
        }
Exemplo n.º 2
0
        public override CommandResult Execute(String arg1, String arg2, String arg3, String arg4)
        {
            if (ClientUser.LevelID != 0)
            {
                List <String> playerlist = MinecraftHandler.Player;
                string        match      = EasyGuess.GetMatchedString(playerlist, arg1);
                if (!String.IsNullOrEmpty(match))
                {
                    long balance = ClientUser.Balance;

                    long money = 0;
                    try
                    {
                        money = Convert.ToInt64(arg2);
                    }
                    catch { }

                    UserCollectionSingletone users = UserCollectionSingletone.GetInstance();
                    User u = users.GetUserByName(match);
                    if (u != null)
                    {
                        return(GiveMoney(u, money));
                    }
                }
                else
                {
                    return(new CommandResult(true, String.Format("User <{0}> not found", arg1)));
                }
            }
            else
            {
                return(new CommandResult(true, String.Format("You don't have an account")));
            }
            return(new CommandResult(true, String.Format("{0} execute by {1}", Name, TriggerPlayer)));
        }
Exemplo n.º 3
0
        public void AddPlayer(String player, int entityId)
        {
            if (!IsStringInList(player, Player))
            {
                Player.Add(player);
                UpdatePlayer(player, 1);

                foreach (IPlugin plugin in Plugins)
                {
                    try
                    {
                        if (plugin.Enabled)
                        {
                            plugin.OnPlayerJoined(this, player);
                        }
                    }
                    catch
                    {
                        Log.AppendText("Error Executing Plugin OnPlayerJoined()", Log.PluginLog);
                    }
                }

                try
                {
                    UserCollectionSingletone users = UserCollectionSingletone.GetInstance();
                    User user = users.GetUserByName(player);
                    user.LastEntityId = entityId;
                    OnlineUsers.Add(user);
                }
                catch
                {
                    Log.AppendText("Error Adding user at OnlineUsers OnPlayerJoined()", Log.ExceptionsLog);
                }
            }
        }
Exemplo n.º 4
0
        public void RemovePlayer(String player)
        {
            if (IsStringInList(player, Player))
            {
                Player.Remove(player);
                UpdatePlayer(player, 0);

                foreach (IPlugin plugin in Plugins)
                {
                    try
                    {
                        if (plugin.Enabled)
                        {
                            plugin.OnPlayerLeft(this, player);
                        }
                    }
                    catch
                    {
                        Log.AppendText("Error Executing Plugin OnPlayerLeft()", Log.PluginLog);
                    }
                }

                try
                {
                    UserCollectionSingletone users = UserCollectionSingletone.GetInstance();
                    OnlineUsers.Remove(users.GetUserByName(player));
                }
                catch
                {
                    Log.AppendText("Error Removing user at OnlineUsers OnPlayerLeft()", Log.ExceptionsLog);
                }
            }
        }
Exemplo n.º 5
0
        public CommandResult CommandHandlerExternal(String userName, String command, String args, ClientSocket client, ServerSocket server)
        {
            if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(command))
            {
                return(null);
            }

            string username = userName;

            try
            {
                CommandManager helper = CommandManager.GetInstance(this);

                String commandMatch = EasyGuess.GetMatchedCommand(helper, command);
                if (String.IsNullOrEmpty(commandMatch))
                {
                    return(null);
                }

                Command c = helper.Items[commandMatch];
                if (c != null)
                {
                    UserCollectionSingletone userCollection = UserCollectionSingletone.GetInstance();
                    User user = userCollection.GetUserByName(userName);
                    if (user == null)
                    {
                        user = new User(userName);
                    }

                    if (user != null && user.Level.IsCommandInList(commandMatch))
                    {
                        string arg1 = "", arg2 = "", arg3 = "";
                        GetArgs(args, out arg1, out arg2, out arg3);
                        c.ClientUser    = user;
                        c.RegArg        = args;
                        c.Client        = client;
                        c.Server        = server;
                        c.TriggerPlayer = userName;
                        CommandResult result;

                        if (arg1.Length > 0 && arg1[0] == '?')
                        {
                            result = c.ExecuteHelp();
                        }
                        else
                        {
                            result = c.Execute(arg1, arg2, arg3, userName);
                        }

                        return(result);
                    }
                }
            }
            catch
            {}
            return(new CommandResult());
        }
Exemplo n.º 6
0
 /// <summary>
 /// this is the execution method which gets executed later
 /// to get more arguments use the internal regArgs variable
 /// </summary>
 /// <param name="arg1">first argument after the command in the string</param>
 /// <param name="arg2">second argument after the command in the string</param>
 /// <param name="arg3">third argument after the command in the string</param>
 /// <param name="arg4">fourth argument after the command in the string</param>
 /// <returns>remember to set the command result in every return case</returns>
 public override CommandResult Execute(String arg1, String arg2, String arg3, String arg4)
 {
     if (!String.IsNullOrEmpty(arg1))
     {
         IMinecraftHandler mc    = MinecraftHandler;
         String            match = EasyGuess.GetMatchedString(mc.Player, arg1);
         if (!String.IsNullOrEmpty(match))
         {
             UserCollectionSingletone userCollection = UserCollectionSingletone.GetInstance();
             User matchedPlayer = userCollection.GetUserByName(match);
             if (matchedPlayer != null)
             {
                 GroupCollectionSingletone groups = GroupCollectionSingletone.GetInstance();
                 Group group = EasyGuess.GetMatchedGroup(groups, arg2);
                 if (group != null)
                 {
                     if (ClientUser.LevelID >= matchedPlayer.LevelID && ClientUser.LevelID >= group.Id) // checks if the triggered user has a higher group level
                     {
                         matchedPlayer.LevelID = group.Id;                                              // sets the rank to the user :)
                         if (matchedPlayer.Generated)
                         {
                             matchedPlayer.Name = match;
                             if (!userCollection.IsInlist(match))
                             {
                                 userCollection.Add(matchedPlayer);
                                 userCollection.Save();
                             }
                         }
                         return(new CommandResult(true, string.Format("player {0} set to group {1}", matchedPlayer.Name, group.Name)));
                     }
                     else
                     {
                         return(new CommandResult(true, string.Format("group level is too low {0} ID:{1}", ClientUser.Level.Name, ClientUser.LevelID)));
                     }
                 }
                 else
                 {
                     return(new CommandResult(true, string.Format("couldn't find group {0}", arg2))); // give as much informations as you can
                 }
             }
             else
             {
                 return(new CommandResult(true, string.Format("couldn't find the user {0}", match))); // give as much informations as you can
             }
         }
         else
         {
             return(new CommandResult(true, string.Format("couldn't find the user {0}", match))); // give as much informations as you can
         }
     }
     else
     {
         return(new CommandResult(true, string.Format("couldn't find player {0}", arg1)));
     }
 }
Exemplo n.º 7
0
        public void UpdatePlayer(MinecraftHandler mc, String playerName, int isOnline)
        {
            if (mc.Config.StreamEnabled)
            {
                try
                {
                    string name          = mc.Config.ServerName;
                    String guid          = mc.Config.GuidString;
                    int    id            = GetServerId(guid);
                    int    online        = isOnline;
                    int    secondsOnline = mc.SecondsOnline;
                    //int playersMax = 100;
                    int      playersOnline = mc.Player.Count;
                    string   ip            = mc.Config.ExternalIp;
                    int      port          = mc.Config.ExternalPort;
                    DateTime dt            = DateTime.Now;

                    UserCollectionSingletone users = UserCollectionSingletone.GetInstance();
                    User u            = users.GetUserByName(playerName);
                    int  hasWebAccess = u.HasWebAccess ? 1 : 0;
                    if (u.Generated)
                    {
                        hasWebAccess = 0;
                    }

                    if (!IsInTable("zma_players", "name", playerName))
                    {
                        String query = String.Format("INSERT INTO zma_players " +
                                                     "(is_online,name,seconds_online,date_last_online, fk_server_id, web_login, web_password, has_web_access,fk_web_server_guid) " +
                                                     "VALUES ({0},'{1}',{2}, {3},{4},'{5}',MD5('{6}'),{7},{8});",
                                                     online,
                                                     playerName,
                                                     secondsOnline,
                                                     "NOW()",
                                                     id,
                                                     u.WebUsername,
                                                     u.PasswordHash,
                                                     hasWebAccess,
                                                     id
                                                     );
                        ExecuteSQL(query);
                    }
                    else
                    {
                        String query = String.Format("UPDATE zma_players SET " +
                                                     "seconds_online = {0} ," +
                                                     "date_last_online = {1}, " +
                                                     "is_online = {2}, " +
                                                     "fk_server_id = {3}, " +
                                                     "web_login = '******', " +
                                                     "web_password = MD5('{5}'), " +
                                                     "has_web_access = {6}, " +
                                                     "fk_web_server_guid = {7} " +
                                                     "WHERE name = '{8}';",
                                                     secondsOnline, "NOW()", online, id, u.WebUsername, u.PasswordHash, hasWebAccess, id, playerName
                                                     );
                        ExecuteSQL(query);
                    }
                }
                catch (Exception ex)
                {
                    Log.Append(this, ex.Message, Log.ExceptionsLog);
                }
            }
        }
Exemplo n.º 8
0
        public void GetCommands(MinecraftHandler mc, LockFreeQueue <WebActionCommand> webCommands)
        {
            try
            {
                if (mc.Started && mc.Config.StreamEnabled)
                {
                    String guid = mc.Config.GuidString;

                    MySqlCommand command = connection.CreateCommand();
                    String       sql     = String.Format(
                        "SELECT * FROM zma_app.zma_web_queue w WHERE w.server_guid = '{0}';"
                        , guid);
                    command.CommandText = sql;
                    MySqlDataReader reader = command.ExecuteReader();
                    List <int>      ids    = new List <int>();

                    int id = -1;

                    while (reader.Read())
                    {
                        id = reader.GetInt32("id");
                        WebActionType type = WebActionType.None;
                        type = (WebActionType)reader.GetInt32("type");
                        string message = "";
                        message = reader.GetString("message");
                        UserCollectionSingletone users = UserCollectionSingletone.GetInstance();

                        String userName = "";
                        try
                        {
                            userName = reader.GetString("name");
                        }
                        catch
                        {
                        }

                        if (id >= 0)
                        {
                            ids.Add(id);
                        }

                        User user = users.GetUserByName(userName);
                        if (type == WebActionType.Chat && id >= 0 && !user.Generated)
                        {
                            WebActionCommand cmd = new WebActionCommand(id, type, message, user, this);
                            webCommands.Enqueue(cmd);
                        }
                    }

                    reader.Close();

                    foreach (int i in ids)
                    {
                        command.CommandText = String.Format("DELETE FROM zma_app.zma_web_queue WHERE id = {0};", i);
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Append(this, "GetCommands " + ex.Message, Log.ExceptionsLog);
            }
        }
Exemplo n.º 9
0
 public override CommandResult Execute(String arg1, String arg2, String arg3, String arg4)
 {
     if (!String.IsNullOrEmpty(arg1))
     {
         UserCollectionSingletone userlist = UserCollectionSingletone.GetInstance();
         if (arg1[0] == '*')
         {
             if (arg1 == "*true")
             {
                 foreach (User u in userlist.Items)
                 {
                     if (ClientUser != u)
                     {
                         u.AllowChat = false;
                     }
                 }
                 Server.SendServerMessage(String.Format("Every player has been muted except {0}", TriggerPlayer));
             }
             if (arg1 == "*false")
             {
                 foreach (User u in userlist.Items)
                 {
                     if (ClientUser != u)
                     {
                         u.AllowChat = true;
                     }
                 }
                 Server.SendServerMessage(String.Format("Every player has been unmuted except {0}", TriggerPlayer));
             }
         }
         else
         {
             List <String> playerlist = MinecraftHandler.Player;
             string        match      = EasyGuess.GetMatchedString(playerlist, arg1);
             if (!String.IsNullOrEmpty(match))
             {
                 User user = userlist.GetUserByName(match);
                 if (user.Generated)
                 {
                     user.Generated = false;
                     userlist.Add(user);
                     user.AllowChat = false;
                     userlist.Save();
                     return(new CommandResult(true, string.Format("{0} has muted {1}", TriggerPlayer, match)));
                 }
                 else
                 {
                     user.AllowChat = !user.AllowChat;
                     userlist.Save();
                     if (user.AllowChat)
                     {
                         return(new CommandResult(true, string.Format("{0} has unmuted {1}", TriggerPlayer, match)));
                     }
                     else
                     {
                         return(new CommandResult(true, string.Format("{0} has muted {1}", TriggerPlayer, match)));
                     }
                 }
             }
         }
     }
     return(new CommandResult(true, string.Format("user not found {0}", arg1)));
 }