private void recv(string msg)
        {
            if (State == WebSockState.Connecting)
            {
                if (ci.cii == null)
                {
                    ci.cii = new Dictionary<string, string>();
                    ci.cii.Add("nick", ci.nick);
                    ci.cii.Add("room", ci.room);
                }

                Send(make_msg("join", ci.cii));
                State = WebSockState.Connected;
            }
            else if (msg == "2::")
            {
                Send("2::");
            }
            else
            {
                msg = msg.Substring(4);
                Newtonsoft.Json.JsonTextReader JTR = new Newtonsoft.Json.JsonTextReader(new System.IO.StringReader(msg));

                char name_type = '\0';
                Dictionary<string, string> args = new Dictionary<string, string>(5);

                while (JTR.Read())
                {
                    switch (JTR.ValueType == typeof(string) ? (string)JTR.Value : "")
                    {
                        case "name":
                            name_type = JTR.ReadAsString()[0];
                            break;
                        case "args":
                            switch (name_type)
                            {
                                case 'u':
                                    JTR.Read();
                                    JTR.Read();
                                    JTR.Read();

                                    switch (JTR.ReadAsString())
                                    {
                                        case "l":
                                            Dictionary<string, user_info> ui = new Dictionary<string,user_info>(8);
                                            JTR.Read();
                                            JTR.Read();
                                            while (JTR.Read())
                                            {
                                                string nick = (string)JTR.Value;
                                                user_info lui = new user_info();
                                                JTR.Read();
                                                while (JTR.Read() && JTR.Value != null && JTR.ValueType.ToString() != "EndObject")
                                                {
                                                    switch ((string)JTR.Value)
                                                    {
                                                        case "a":
                                                            lui.admin = JTR.ReadAsInt32() == 0 ? false : true;
                                                            break;
                                                        case "t":
                                                            lui.conn = (DateTime)JTR.ReadAsDateTime();
                                                            break;
                                                        case "m":
                                                            lui.mb_id = JTR.ReadAsString();
                                                            break;
                                                        case "l":
                                                            lui.login = JTR.ReadAsInt32() == 1 ? false : true;
                                                            break;

                                                        default:
                                                            JTR.Read();
                                                            break;
                                                    }
                                                }

                                                if(nick != null) ui.Add(nick, lui);
                                            }
                                            break;
                                        default:
                                            break;
                                    }

                                    break;

                                case 'c':
                                    JTR.Skip();
                                    JTR.Skip();

                                    while (JTR.Read())
                                    {
                                        args.Add((string)JTR.Value, JTR.ReadAsString());
                                    }
                                    break;

                                default:
                                    break;
                            }

                            break;

                        default:
                            break;
                    }
                }
            }
        }
Beispiel #2
0
        private void recv(string msg)
        {
            if (State == WebSockState.Connecting)
            {
                if (ci.cii == null)
                {
                    ci.cii = new Dictionary <string, string>();
                    ci.cii.Add("nick", ci.nick);
                    ci.cii.Add("room", ci.room);
                }

                Send(make_msg("join", ci.cii));
                State = WebSockState.Connected;
            }
            else if (msg == "2::")
            {
                Send("2::");
            }
            else
            {
                msg = msg.Substring(4);
                Newtonsoft.Json.JsonTextReader JTR = new Newtonsoft.Json.JsonTextReader(new System.IO.StringReader(msg));

                char name_type = '\0';
                Dictionary <string, string> args = new Dictionary <string, string>(5);

                while (JTR.Read())
                {
                    switch (JTR.ValueType == typeof(string) ? (string)JTR.Value : "")
                    {
                    case "name":
                        name_type = JTR.ReadAsString()[0];
                        break;

                    case "args":
                        switch (name_type)
                        {
                        case 'u':
                            JTR.Read();
                            JTR.Read();
                            JTR.Read();

                            switch (JTR.ReadAsString())
                            {
                            case "l":
                                Dictionary <string, user_info> ui = new Dictionary <string, user_info>(8);
                                JTR.Read();
                                JTR.Read();
                                while (JTR.Read())
                                {
                                    string    nick = (string)JTR.Value;
                                    user_info lui  = new user_info();
                                    JTR.Read();
                                    while (JTR.Read() && JTR.Value != null && JTR.ValueType.ToString() != "EndObject")
                                    {
                                        switch ((string)JTR.Value)
                                        {
                                        case "a":
                                            lui.admin = JTR.ReadAsInt32() == 0 ? false : true;
                                            break;

                                        case "t":
                                            lui.conn = (DateTime)JTR.ReadAsDateTime();
                                            break;

                                        case "m":
                                            lui.mb_id = JTR.ReadAsString();
                                            break;

                                        case "l":
                                            lui.login = JTR.ReadAsInt32() == 1 ? false : true;
                                            break;

                                        default:
                                            JTR.Read();
                                            break;
                                        }
                                    }

                                    if (nick != null)
                                    {
                                        ui.Add(nick, lui);
                                    }
                                }
                                break;

                            default:
                                break;
                            }

                            break;

                        case 'c':
                            JTR.Skip();
                            JTR.Skip();

                            while (JTR.Read())
                            {
                                args.Add((string)JTR.Value, JTR.ReadAsString());
                            }
                            break;

                        default:
                            break;
                        }

                        break;

                    default:
                        break;
                    }
                }
            }
        }