示例#1
0
文件: Listener.cs 项目: hzsydy/jiwang
 public void changeName(string oldname, string newname)
 {
     lock (thisLock)
     {
         if (reg_chatlinks.ContainsKey(oldname))
         {
             ChatLink cl = reg_chatlinks[oldname];
             reg_chatlinks.Remove(oldname);
             reg_chatlinks.Add(newname, cl);
             refreshFriendList();
         }
     }
 }
示例#2
0
文件: Listener.cs 项目: hzsydy/jiwang
 public void unregister(string chatname)
 {
     lock (thisLock)
     {
         if (reg_chatlinks.ContainsKey(chatname))
         {
             ChatLink cl = reg_chatlinks[chatname];
             cl.stop();
             reg_chatlinks.Remove(chatname);
             refreshFriendList();
         }
     }
 }
示例#3
0
文件: Listener.cs 项目: hzsydy/jiwang
 public ChatLink register(string chatname)
 {
     lock (thisLock)
     {
         if (!reg_chatlinks.ContainsKey(chatname))
         {
             ChatLink new_cl = new ChatLink(sl, this, chatname);
             reg_chatlinks.Add(chatname, new_cl);
             if (form != null)
             {
                 form.BeginInvoke((Action) delegate { form.refreshFriendList(reg_chatlinks); });
             }
         }
         ChatLink cl = reg_chatlinks[chatname];
         return(cl);
     }
 }
示例#4
0
文件: Listener.cs 项目: hzsydy/jiwang
        bool parseStateData(StateObject state)
        {
            Console.WriteLine("receive:" + common.ascii2Str(state.data));
            if (state.data.Count >= common.msg_position)
            {
                List <byte> msg_len_header = state.data.GetRange(common.msglen_position, common.msglen_length);
                int         msg_len        = Convert.ToInt32(common.ascii2Str(msg_len_header));

                int expect_len = common.msg_position + msg_len;

                if (state.data.Count >= expect_len)
                {
                    //all data received. parse it

                    List <byte> type_header = state.data.GetRange(0, common.type_header_length);
                    List <byte> name_header = state.data.GetRange(
                        common.type_header_length, common.name_header_length);
                    List <byte> msg = state.data.GetRange(common.msg_position, msg_len);

                    string type_str = common.ascii2Str(type_header);
                    string chatname = common.ascii2Str(name_header);

                    lock (thisLock)
                    {
                        if (type_str != common.type_str_quit_group)
                        {
                            ChatLink cl = register(chatname);
                            cl.onReceive(type_str, msg.ToArray());
                        }
                        else
                        {
                            if (reg_chatlinks.ContainsKey(chatname))
                            {
                                ChatLink cl = register(chatname);
                                cl.onReceive(type_str, msg.ToArray());
                            }
                        }
                    }


                    List <byte> left_msg = state.data.GetRange(expect_len,
                                                               state.data.Count - expect_len);
                    if (left_msg.Count == 0)
                    {
                        state.data = new List <byte>();
                    }
                    else
                    {
                        int notzero = left_msg.FindIndex((x) => x > 0);
                        if (notzero >= 0)
                        {
                            state.data = left_msg.GetRange(notzero, left_msg.Count - notzero);
                        }
                        else
                        {
                            state.data = new List <byte>();
                        }
                    }
                    state.buffer = new byte[common.buffersize];
                    return(true);
                }
            }
            return(false);
        }