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);
            }
        }
Example #2
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);
            }
        }