public string getCustomSetting(string settingname)
        {
            JSONWriter writer = new JSONWriter();

            writer.WriteStartArray();
            foreach (CustomSetting setting in CustomSettings)
            {
                if (setting.SettingName == settingname.ToLower())
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("Name");
                    writer.WriteValue(setting.SettingName);
                    writer.WritePropertyName("Private");
                    writer.WriteValue(setting.Private);
                    writer.WritePropertyName("Value");
                    writer.WriteValue(setting.Value);
                    writer.WriteEndObject();

                    break;
                }
            }
            writer.WriteEndArray();

            return(writer.GetString());
        }
        public void SerializeJson(JSONWriter writer)
        {
            writer.WriteStartArray();

            lineInfos.ForEach(x => x.SerializeJson(writer));

            writer.WriteEndArray();
        }
        public string getPlugin(string filenamewithoutextension)
        {
            foreach (PluginJS plugin in tmch.Plugins)
            {
                if (plugin.PluginName == filenamewithoutextension)
                {
                    JSONWriter writer = new JSONWriter();

                    writer.WriteStartObject();
                    writer.WritePropertyName("PluginName");
                    writer.WriteValue(plugin.PluginName);

                    writer.WritePropertyName("AddedCommands");
                    writer.WriteStartArray();

                    foreach (string addedcommand in plugin.AddedCommands)
                    {
                        writer.WriteValue(addedcommand);
                    }

                    writer.WriteEndArray();

                    writer.WritePropertyName("HandledEvents");
                    writer.WriteStartArray();

                    foreach (string handledevent in plugin.HandledEvents)
                    {
                        writer.WriteValue(handledevent);
                    }

                    writer.WriteEndArray();
                    writer.WriteEndObject();

                    return(writer.GetString());
                }
            }

            return(string.Empty);
        }
        public string getCustomSettings()
        {
            JSONWriter writer = new JSONWriter();

            writer.WriteStartArray();
            foreach (CustomSetting setting in CustomSettings)
            {
                writer.WriteRaw(getCustomSetting(setting.SettingName));
            }

            writer.WriteEndArray();

            return(writer.GetString());
        }
        public string getPlugins()
        {
            JSONWriter writer = new JSONWriter();

            writer.WriteStartArray();

            foreach (PluginJS plugin in tmch.Plugins)
            {
                writer.WriteRaw(getPlugin(plugin.PluginName) + ',');
            }

            writer.WriteEndArray();

            return(writer.GetString());
        }
        public string getExtensions()
        {
            JSONWriter writer = new JSONWriter();

            writer.WriteStartArray();

            foreach (PluginNET plugin in extloader.Plugins)
            {
                writer.WriteRaw(getExtension(plugin.PluginName) + ',');
            }

            writer.WriteEndArray();

            return(writer.GetString());
        }
        public string getClients()
        {
            JSONWriter writer = new JSONWriter();

            writer.WriteStartArray();

            foreach (Client client in Clients)
            {
                writer.WriteRaw(getClient((int)client.ID) + ',');
            }

            writer.WriteEndArray();

            return(writer.GetString());
        }
        public string getClient(int playerid)
        {
            foreach (Client client in Clients)
            {
                if (client.ID == playerid)
                {
                    JSONWriter writer = new JSONWriter();

                    writer.WriteStartObject();
                    writer.WritePropertyName("ID");
                    writer.WriteValue(client.ID);
                    writer.WritePropertyName("AvgCosts");
                    writer.WriteValue(client.AvgCosts);
                    writer.WritePropertyName("AvgIncome");
                    writer.WriteValue(client.AvgIncome);
                    writer.WritePropertyName("AvgScore");
                    writer.WriteValue(client.AvgScore);
                    writer.WritePropertyName("Boss");
                    writer.WriteValue(client.Boss);
                    writer.WritePropertyName("Cash");
                    writer.WriteValue(client.Cash);
                    writer.WritePropertyName("Code");
                    writer.WriteValue(client.Code);
                    writer.WritePropertyName("CurrentWeek");
                    writer.WriteValue(client.CurrentWeek);
                    writer.WritePropertyName("Employees");
                    writer.WriteValue(client.Employees);
                    writer.WritePropertyName("Fans");
                    writer.WriteValue(client.Fans);
                    writer.WritePropertyName("FavouriteGenre");
                    writer.WriteValue(client.FavouriteGenre);
                    writer.WritePropertyName("GameCount");
                    writer.WriteValue(client.GameCount);
                    writer.WritePropertyName("HighScore");
                    writer.WriteValue(client.HighScore);
                    writer.WritePropertyName("IP");
                    writer.WriteValue(client.Context.ConnectionInfo.ClientIpAddress);

                    writer.WritePropertyName("Mods");
                    writer.WriteStartArray();
                    foreach (ClientMod mod in client.Mods)
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("ID");
                        writer.WriteValue(mod.ID);
                        writer.WritePropertyName("Name");
                        writer.WriteValue(mod.Name);
                        writer.WriteEndObject();
                    }
                    writer.WriteEndArray();

                    writer.WritePropertyName("Name");
                    writer.WriteValue(client.Name);
                    writer.WritePropertyName("Op");
                    writer.WriteValue(client.Op);
                    writer.WritePropertyName("PlatformCount");
                    writer.WriteValue(client.PlatformCount);
                    writer.WritePropertyName("Port");
                    writer.WriteValue(client.Context.ConnectionInfo.ClientPort);
                    writer.WritePropertyName("ResearchPoints");
                    writer.WriteValue(client.ResearchPoints);
                    writer.WriteEndObject();

                    return(writer.GetString());
                }
            }

            return(string.Empty);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 
        /// </summary>
        public static void SerializeRPC(string id, object error, object obj, Stream stream)
        {
            JSONWriter writer = new JSONWriter(new StreamWriter(stream));

            // Start JSON output
            writer.WriteStartObject();
            writer.WritePropertyName("result");

            // Serialize result set
            if (obj is Moxiecode.Manager.Utils.ResultSet) {
                ResultSet rs = (ResultSet) obj;

                writer.WriteStartObject();

                // Write header
                writer.WritePropertyName("header");
                writer.WriteStartObject();

                foreach (string key in rs.Header.Keys) {
                    writer.WritePropertyName(key);
                    writer.WriteValue(rs.Header[key]);
                }

                writer.WriteEndObject();

                // Write columns
                writer.WritePropertyName("columns");
                writer.WriteStartArray();

                foreach (string col in rs.Columns)
                    writer.WriteValue(col);

                writer.WriteEndArray();

                // Write data
                writer.WritePropertyName("data");
                writer.WriteStartArray();

                foreach (ArrayList row in rs.Data) {
                    writer.WriteStartArray();

                    foreach (object item in row)
                        WriteValue(writer, item);

                    writer.WriteEndArray();
                }

                writer.WriteEndArray();

                // Write config
                if (rs.Config != null) {
                    writer.WritePropertyName("config");
                    writer.WriteStartObject();

                    foreach (string key in rs.Config.AllKeys) {
                        writer.WritePropertyName(key);
                        writer.WriteValue(rs.Config[key]);
                    }

                    writer.WriteEndObject();
                }

                // End result
                writer.WriteEndObject();
            } else
                WriteValue(writer, obj);

            // Write id
            writer.WritePropertyName("id");
            writer.WriteValue(id);

            // Write error
            writer.WritePropertyName("error");
            writer.WriteValue(null);

            // Close
            writer.WriteEndObject();
            writer.Close();
        }
Ejemplo n.º 10
0
        private static void WriteValue(JSONWriter writer, object obj)
        {
            if (obj == null)
                writer.WriteNull();

            if (obj is System.String)
                writer.WriteValue((string) obj);

            if (obj is System.Boolean)
                writer.WriteValue((bool) obj);

            if (obj is System.Double)
                writer.WriteValue(Convert.ToDouble(obj));

            if (obj is System.Int32)
                writer.WriteValue(Convert.ToInt32(obj));

            if (obj is System.Int64)
                writer.WriteValue(Convert.ToInt64(obj));

            if (obj is ArrayList) {
                writer.WriteStartArray();

                foreach (object val in ((ArrayList) obj))
                    WriteValue(writer, val);

                writer.WriteEndArray();
            }

            if (obj is NameValueCollection) {
                writer.WriteStartObject();

                string[] keys = GetReversedKeys(obj);
                foreach (string key in keys) {
                    writer.WritePropertyName(key);
                    WriteValue(writer, ((NameValueCollection) obj)[key]);
                }

                writer.WriteEndObject();
            }

            if (obj is Hashtable) {
                writer.WriteStartObject();

                string[] keys = GetReversedKeys(obj);
                foreach (string key in keys) {
                    writer.WritePropertyName((string) key);
                    WriteValue(writer, ((Hashtable) obj)[key]);
                }

                writer.WriteEndObject();
            }
        }