/*消息解析
         * */
        public int parseMsg()
        {
            try
            {
                switch (msgStruct.ID())
                {
                case protocol.GW_LOGIN_ACK:
                {
                    int res = 0;
                    //m_msg >> res;
                    if (res == (int)protocol.RET_OK)
                    {
                        //Console.WriteLine("登录成功");
                    }
                    else
                    {
                        MessageBox.Show("登录失败");
                    }
                }
                break;

                case protocol.GM_CHANNELLIST_ACK:
                {
                    //M_SDO.Notice notice = new M_SDO.Notice();
                    int  nChan    = 0;
                    byte bHasMore = 0;

                    nChan    = (int)msgStruct.ReadData(nChan, 4);
                    bHasMore = Convert.ToByte(msgStruct.ReadData(bHasMore, 1));
                    //Console.WriteLine("收到频道信息"+nChan+"个");
                    for (int i = 0; i < nChan; i++)
                    {
                        wPlanetID    = Convert.ToInt16(msgStruct.ReadData(wPlanetID, 2));
                        wChannelID   = Convert.ToInt16(msgStruct.ReadData(wChannelID, 2));
                        iLimitUser   = (int)msgStruct.ReadData(iLimitUser, 4);
                        iCurrentUser = (int)msgStruct.ReadData(iCurrentUser, 4);
                        ipaddr       = Convert.ToString(msgStruct.ReadData(ipaddr, 15));
                        iItemIndex   = i;

                        _form.Invoke(new EventHandler(ReLoadChannel1));
                        //this._listView.Invoke(new LoadChannel(ToLoadChannel));

                        // LoadChannel loadChannel = new LoadChannel(notice.ToLoadChannel);
                        // loadChannel(i, wPlanetID, wChannelID, iLimitUser, iCurrentUser, ipaddr, this._form);
                        //Console.WriteLine(wPlanetID+"/"+wChannelID+"/"+iLimitUser+"/"+iCurrentUser+"/");
                        //this._listView.Items.Add(wPlanetID.ToString() + "/" + wChannelID.ToString() + "/" + iLimitUser.ToString() + "/" + iCurrentUser.ToString() + "/" + ipaddr);
                        //this._listView.Items[i].Tag = wPlanetID.ToString() + "/" + wChannelID.ToString() + "/" + iLimitUser.ToString() + "/" + iCurrentUser.ToString() + "/" + ipaddr;
                        //Console.WriteLine(ipaddr);
                    }
                    Thread.CurrentThread.Abort();
                }
                break;

                case protocol.EH_ALIVE_REQ:
                {
                    msgStruct = new CMsg((short)protocol.EH_ALIVE_ACK);
                    send_msg(msgStruct);
                }
                break;

                default:
                    //Console.WriteLine("Unknown Message Received:"+msgStruct.ID());
                    break;
                    //////m_debugList.AddString(debugString);
                }
            }
            catch { }
            return(0);
        }
Example #2
0
        /*消息解析
         * */
        void parseMsg()
        {
            switch (msgStruct.ID())
            {
            case protocol.GW_LOGIN_ACK:
            {
                int res = 0;
                //m_msg >> res;
                if (res == (int)protocol.RET_OK)
                {
                    //Console.WriteLine("登录成功");
                    //发送频道列表请求消息
                    msgStruct = new CMsg((short)protocol.GM_CHANNELLIST_REQ);
                    msgStruct.writeLength(msgStruct.GetSize());
                    client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
                }
                else
                {
                    Console.WriteLine(lg.SDOAPI_SDONoticeInfoAPI_LoginFailure);
                }
            }
            break;

            case protocol.GM_CHANNELLIST_ACK:
            {
                int    nChan = 0;
                byte   bHasMore = 0;
                short  wPlanetID = 0, wChannelID = 0;
                int    iLimitUser = 0, iCurrentUser = 0;
                string ipaddr = "";
                nChan    = (int)msgStruct.ReadData(nChan, 4);
                bHasMore = Convert.ToByte(msgStruct.ReadData(bHasMore, 1));
                //Console.WriteLine("收到频道信息"+nChan+"个");

                for (int i = 0; i < nChan; i++)
                {
                    try
                    {
                        //星球ID
                        wPlanetID = Convert.ToInt16(msgStruct.ReadData(wPlanetID, 2));
                        //频道ID
                        wChannelID = Convert.ToInt16(msgStruct.ReadData(wChannelID, 2));
                        //最大限制人数
                        iLimitUser = (int)msgStruct.ReadData(iLimitUser, 4);
                        //当前人数
                        iCurrentUser = (int)msgStruct.ReadData(iCurrentUser, 4);
                        //IP地址
                        ipaddr = Convert.ToString(msgStruct.ReadData(ipaddr, 15));
                        //Console.WriteLine(wPlanetID+"/"+wChannelID+"/"+iLimitUser+"/"+iCurrentUser+"/"+ipaddr+"\n");
                        NoticeDataInfo.InsertChannel_Req(wPlanetID, wChannelID, iLimitUser, iCurrentUser, ipaddr);
                    }
                    catch (System.Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                listCnt++;
            }
            break;

            case protocol.EH_ALIVE_REQ:
            {
                msgStruct = new CMsg((short)protocol.EH_ALIVE_ACK);
                send_msg(msgStruct);
            }
            break;

            default:
                //Console.WriteLine("Unknown Message Received:"+msgStruct.ID());
                break;
            }
        }