Beispiel #1
0
        public void sendBoardMsg_Req()
        {
            int    nChan     = 40;
            string strNotice = null;

            msgStruct = new CMsg((short)protocol.GM_NOTICE_REQ);
            msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(strNotice), strNotice.Length);
            byte[] ret = new byte[] {
                (byte)nChan, (byte)(nChan >> 8)
            };
            msgStruct.WriteData(ret, 4);
            client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
            for (int i = 0; i < nChan; i++)
            {
                ulong itemdata = 0;
                ret = new byte[] {
                    (byte)LOWORD(itemdata), (byte)(LOWORD(itemdata) >> 8)
                };
                msgStruct.WriteData(ret, 2);
                ret = new byte[] {
                    (byte)HIWORD(itemdata), (byte)(HIWORD(itemdata) >> 8)
                };
                msgStruct.WriteData(ret, 2);
            }
            msgStruct.writeLength(msgStruct.GetSize());
            client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
        }
        public void sendBoardMsg_Req(int[,] iArrayPC, string sNotcie)
        {
            int nChan = iArrayPC.GetLength(0);

            string strNotice = sNotcie;

            msgStruct = new CMsg((short)protocol.GM_NOTICE_REQ);

            msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(strNotice), strNotice.Length);

            byte[] ret = new byte[] {
                (byte)nChan, (byte)(nChan >> 8)
            };
            msgStruct.WriteData(ret, 2);

            for (int i = 0; i < nChan; i++)
            {
                //星球
                ret = new byte[] {
                    (byte)iArrayPC[i, 0], (byte)(nChan >> 8)
                };
                msgStruct.WriteData(ret, 2);
                //频道
                ret = new byte[] {
                    (byte)iArrayPC[i, 1], (byte)(nChan >> 8)
                };
                msgStruct.WriteData(ret, 2);
            }
            msgStruct.writeLength(msgStruct.GetSize());
            client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
        }
        public void connect_Req(string serverIP)
        {
            string userName = "******";
            string password = "******";
            short  version  = 1;
            short  version1 = 6;
            int    port     = 15010;

            try
            {
                IPAddress ipAdress = IPAddress.Parse(serverIP);
                client = new Socket(AddressFamily.InterNetwork,
                                    SocketType.Stream,
                                    ProtocolType.Tcp);

                //Console.WriteLine("Establishing Connection to {0}",serverIP);
                IPEndPoint ipReomtePoint = new IPEndPoint(ipAdress, port);

                client.Connect(ipReomtePoint);
                if (client.Connected == true)
                {
                    //Console.WriteLine("Connection established");
                    msgStruct = new CMsg((short)protocol.GW_LOGIN_REQ);
                    msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(userName), userName.Length);
                    msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(password), password.Length);
                    byte[] ret = new byte[] {
                        (byte)version, (byte)(version >> 8)
                    };
                    msgStruct.WriteData(ret, 1);
                    ret = new byte[] {
                        (byte)version1, (byte)(version1 >> 8)
                    };
                    msgStruct.WriteData(ret, 1);
                    msgStruct.writeLength(msgStruct.GetSize());
                    client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
                    ThreadStart wokerStart = new ThreadStart(ReadThreadFunc);
                    Thread      workThread = new Thread(wokerStart);
                    workThread.Start();
                }
            }
            catch (SocketException ex)
            {
                //Console.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #4
0
        //发送公告消息
        public Message SendBoardInfo()
        {
            string serverIP     = null;
            string channelList  = null;
            string boardMessage = null;
            int    userbyID     = 0;
            int    result       = -1;

            try
            {
                serverIP = Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.SDO_ServerIP).m_bValueBuffer);
                //频道列表
                channelList = Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.SDO_ChannelList).m_bValueBuffer);
                //公告信息
                boardMessage = Encoding.Default.GetString(msg.m_packet.m_Body.getTLVByTag(TagName.SDO_BoardMessage).m_bValueBuffer);
                //操作员ID
                TLV_Structure tlvStrut = new TLV_Structure(TagName.UserByID, 3, msg.m_packet.m_Body.getTLVByTag(TagName.UserByID).m_bValueBuffer);
                userbyID = (int)tlvStrut.toInteger();
                connect_Req(serverIP);
                //发公告消息
                msgStruct = new CMsg((short)protocol.GM_NOTICE_REQ);
                msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(boardMessage), boardMessage.Length);
                string[] chanList = channelList.Split(';');
                int      nChan    = chanList.Length;
                byte[]   ret      = new byte[4];
                ret = BitConverter.GetBytes(nChan);
                for (int i = 0; i < nChan; i++)
                {
                    string[] wPlanetList = chanList[i].Split('/');
                    short    wPlanetID   = Convert.ToInt16(wPlanetList[0]);
                    short    wChannelID  = Convert.ToInt16(wPlanetList[1]);
                    ret = new byte[] {
                        (byte)wPlanetID, (byte)(wPlanetID >> 8)
                    };
                    msgStruct.WriteData(ret, 2);
                    ret = new byte[] {
                        (byte)wChannelID, (byte)(wChannelID >> 8)
                    };
                    msgStruct.WriteData(ret, 2);
                }
                msgStruct.writeLength(msgStruct.GetSize());
                client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
                client.Close();
                result = NoticeDataInfo.BoardMessage_Req(userbyID, serverIP, channelList, boardMessage);
                if (result == 1)
                {
                    SqlHelper.log.WriteLog(lg.API_Display + lg.SDOAPI_SDO + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.SDOAPI_SDONoticeInfoAPI_SendNoticeInfo + lg.API_Success + "!");
                    Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.SDOAPI_SDO + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.SDOAPI_SDONoticeInfoAPI_SendNoticeInfo + lg.API_Success + "!");
                    return(Message.COMMON_MES_RESP("SUCESS", Msg_Category.SDO_ADMIN, ServiceKey.SDO_BOARDMESSAGE_REQ_RESP));
                }
                else
                {
                    SqlHelper.log.WriteLog(lg.API_Display + lg.SDOAPI_SDO + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.SDOAPI_SDONoticeInfoAPI_SendNoticeInfo + lg.API_Failure + "!");
                    Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.SDOAPI_SDO + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.SDOAPI_SDONoticeInfoAPI_SendNoticeInfo + lg.API_Failure + "!");
                    return(Message.COMMON_MES_RESP("FAILURE", Msg_Category.SDO_ADMIN, ServiceKey.SDO_BOARDMESSAGE_REQ_RESP));
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                SqlHelper.log.WriteLog(lg.API_Display + lg.SDOAPI_SDO + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.SDOAPI_SDONoticeInfoAPI_SendNoticeInfo + lg.API_Failure + "!");
                Console.WriteLine(DateTime.Now + " - " + lg.API_Display + lg.SDOAPI_SDO + "+>" + lg.API_CommonAPI_ServerIP + CommonInfo.serverIP_Query(serverIP) + lg.SDOAPI_SDONoticeInfoAPI_SendNoticeInfo + lg.API_Failure + "!");
                return(Message.COMMON_MES_RESP("FAILURE", Msg_Category.SDO_ADMIN, ServiceKey.SDO_BOARDMESSAGE_REQ_RESP));
            }
        }