예제 #1
0
        private async Task <ConnectionInfo> InitConnection()
        {
            var buffer = await this.ReadData();

            if (buffer.Split(' ')[0] == "salut" && buffer.Contains("\n"))
            {
                var info = NetsoulHelper.ConnectionInfoParsing(buffer);
                return(info);
            }
            return(null);
        }
예제 #2
0
        protected async Task ParseReceivedData(string buffer)
        {
            if (buffer != null)
            {
                string[] command = buffer.Split(' ');
                switch (command[0])
                {
                case "ping":
                    await this.SendData(buffer);

                    break;

                case "user_cmd":
                    if (buffer.Contains("|"))
                    {
                        string[] userCommand = buffer.Split('|')[1].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        string[] parse       = null;
                        switch (userCommand[0])
                        {
                        case "msg":
                            parse = buffer.Split('|')[1].Split(' ');
                            var msg = "message:" + buffer.Split('|')[0].Split(':')[3].Split('@')[0] + ":"
                                      + buffer.Split('|')[0].Split(':')[0].Split(' ')[1] + ":"
                                      + buffer.Split('|')[0].Split(':')[5] + ":"
                                      + StringToUrlConverter.Convert(parse[2], ConverterMode.UrlToStandard);
                            if (this.OnMessage != null)
                            {
                                this.OnMessage(this, new NetsoulMessageEventArgs(msg));
                            }
                            break;

                        case "who":
                            parse = buffer.Split('|')[1].Split(' ');
                            if (parse[2] == "rep")
                            {
                                break;
                            }
                            //var t1 = parse[3];
                            //var t2 = parse[12].Split(':')[0];
                            //var t3 = parse[10];
                            //var t4 = parse[13].Split('\n')[0];
                            //var t5 = parse[2];
                            if (this.OnContactUpdate != null)
                            {
                                this.OnContactUpdate(this, new NetSoulContactUpdateEventArgs(parse[3], NetsoulHelper.GetStatus(parse[12].Split(':')[0]), parse[10], parse[13].Split('\n')[0], parse[2]));
                            }
                            break;

                        case "login":
                        case "state":
                            parse = command[1].Split(':');
                            var status = userCommand[1].Split(':')[0];
                            if (this.OnContactUpdate != null)
                            {
                                this.OnContactUpdate(this, new NetSoulContactUpdateEventArgs(parse[3].Split('@')[0], NetsoulHelper.GetStatus(status), parse[5], "", parse[0]));
                            }
                            break;

                        case "logout":
                            parse = command[1].Split(':');
                            if (this.OnContactUpdate != null)
                            {
                                this.OnContactUpdate(this, new NetSoulContactUpdateEventArgs(parse[3].Split('@')[0], ContactStatus.Offline, null, null, "-1"));
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
예제 #3
0
 private async Task <bool> SetStatus(ContactStatus status)
 {
     return(await this.SendData(string.Format("user_cmd state {0}\n", NetsoulHelper.GetStatus(status))));
 }