Exemplo n.º 1
0
 public void RemoveEvent(GlobalServerMsg id)
 {
     if (m_handlers.ContainsKey(id))
     {
         m_handlers.Remove(id);
     }
 }
Exemplo n.º 2
0
 //在玩家表格条目中增加一条 (索引,表格结构信息)
 public void addRecordItem(GlobalServerMsg id, Record type)
 {
     if (m_recordInfo.ContainsKey(id))
     {
         LogSystem.LogError("Repeat protperty item is ", id);
         m_recordInfo.Remove(id);
     }
     m_recordInfo.Add(id, type);
 }
Exemplo n.º 3
0
 //在玩家属性表条目中增加一条 (索引,属性)
 public void addPropTableItem(GlobalServerMsg id, Propetry type)
 {
     if (m_propertyTable.ContainsKey(id))
     {
         LogSystem.LogError("Repeat protperty item is ", id);
         m_propertyTable.Remove(id);
     }
     m_propertyTable.Add(id, type);
 }
Exemplo n.º 4
0
 private bool AddEvent(GlobalServerMsg id, MsgEevent msg)
 {
     if (m_handlers.ContainsKey(id))
     {
         m_handlers.Remove(id);
     }
     m_handlers.Add(id, msg);
     return(true);
 }
Exemplo n.º 5
0
 //获取玩家表格条目中对应索引号的表格信息
 public bool getRecordItem(GlobalServerMsg id, ref Record type)
 {
     if (!m_recordInfo.ContainsKey(id))
     {
         LogSystem.LogError("Repeat protperty item is ", id);
         return(false);
     }
     type = m_recordInfo[id];
     return(true);
 }
Exemplo n.º 6
0
 //玩家属性表条目中获取对应索引的属性信息
 public bool getPropTableItem(GlobalServerMsg id, ref Propetry type)
 {
     if (!m_propertyTable.ContainsKey(id))
     {
         LogSystem.Log("has not found prop index ", id);
         return(false);
     }
     type = m_propertyTable[id];
     return(true);
 }
Exemplo n.º 7
0
        /// <summary>
        /// 先按简单协议还原数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public int InnerSimpleProtocal(ref Byte[] data, int len)
        {
            if (data.Length == 0 || 0 == len)
            {
                //长度错误
                return(len);
            }
            GlobalServerMsg nMsgType = (GlobalServerMsg)data[0];

            switch (nMsgType)
            {
            case GlobalServerMsg.SERVER_OBJECT_PROPERTY:
            {
                len = proc_server_object_property(ref data, len);
            }
            break;

            case GlobalServerMsg.SERVER_RECORD_GRID:
            {
                len = proc_server_record_grid(ref data, len);
            }
            break;

            case GlobalServerMsg.SERVER_RECORD_ADDROW:
            {
                len = proc_server_record_addrow(ref data, len);
            }
            break;

            case GlobalServerMsg.SERVER_RECORD_DELROW:
            {
                len = proc_server_record_delrow(ref data, len);
            }
            break;

            case GlobalServerMsg.SERVER_LOCATION:
            {
                len = proc_server_location(ref data, len);
            }
            break;

            case GlobalServerMsg.SERVER_MOVING:
            {
                len = proc_server_moving(ref data, len);
            }
            break;

            case GlobalServerMsg.SERVER_ALL_DEST:
            {
                len = proc_server_all_dest(ref data, len);
            }
            break;
            }
            return(len);
        }
Exemplo n.º 8
0
        public void ExcuteEvent(GlobalServerMsg id, object args, int ilen)
        {
            if (!m_handlers.ContainsKey(id))
            {
                LogSystem.Log("DispatchNow: has not id matched for:", id);
                return;
            }

            MsgEevent handler = m_handlers[id];

            if (handler != null)
            {
                try
                {
                    handler(id, args, ilen);
                }
                catch (System.Exception ex)
                {
                    LogSystem.LogError("ExcuteEvent: handler exception:", id, " ", ex.ToString());
                }
            }
        }
Exemplo n.º 9
0
        public void HandleMessage(byte[] data, int size)
        {
            if (data.Length == 0 || 0 == size)
            {
                LogSystem.LogError("Error, HandleMessage data is 0 ");
                return;
            }
            GlobalServerMsg protocolId    = (GlobalServerMsg)data[0];
            bool            is_compressed = false;

            switch (protocolId)
            {
            case GlobalServerMsg.SERVER_MSG_BATCH_COMPRESS:
            {
                protocolId    = GlobalServerMsg.SERVER_MSG_BATCH_COMPRESS;
                is_compressed = true;
            }
            break;

            case GlobalServerMsg.SERVER_IDLE:
            {
                return;          //不处理
            }

            case GlobalServerMsg.SERVER_CP_LOGIN_SUCCEED:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_LOGIN_SUCCEED;
                break;

            case GlobalServerMsg.SERVER_CP_PROPERTY_TABLE:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_PROPERTY_TABLE;
                break;

            case GlobalServerMsg.SERVER_CP_RECORD_TABLE:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_RECORD_TABLE;
                break;

            case GlobalServerMsg.SERVER_CP_CUSTOM:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_CUSTOM;
                break;

            case GlobalServerMsg.SERVER_CP_ADD_OBJECT:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_ADD_OBJECT;
                break;

            case GlobalServerMsg.SERVER_CP_RECORD_ADDROW:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_RECORD_ADDROW;
                break;

            case GlobalServerMsg.SERVER_CP_VIEW_ADD:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_VIEW_ADD;
                break;

            case GlobalServerMsg.SERVER_CP_ALL_DEST:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_ALL_DEST;
                break;

            case GlobalServerMsg.SERVER_CP_ALL_DEST_EX:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_ALL_DEST_EX;
                break;

            case GlobalServerMsg.SERVER_CP_ALL_PROP:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_ALL_PROP;
                break;

            case GlobalServerMsg.SERVER_CP_ADD_MORE_OBJECT:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_ADD_MORE_OBJECT;
                break;

            case GlobalServerMsg.SERVER_CP_LOCATION_GRID:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_LOCATION_GRID;
                break;

            case GlobalServerMsg.SERVER_CP_MOVING_GRID:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_MOVING_GRID;
                break;

            case GlobalServerMsg.SERVER_CP_ALL_DEST_GRID:
                is_compressed = true;
                protocolId    = GlobalServerMsg.SERVER_ALL_DEST_GRID;
                break;

            default:
                is_compressed = false;
                break;
            }

            if (is_compressed)
            {
                int origin_size = QuickLZ.sizeDecompressed(data);
                if (origin_size > (65535 - 1))
                {
                    LogSystem.Log("(GameReceiver::ProcessMessage)decompress size error");
                    return;
                }

                data    = QuickLZ.decompress(data);
                data[0] = System.Convert.ToByte(protocolId);
                size    = origin_size + 1;
            }
            if (GlobalServerMsg.SERVER_MSG_BATCH_COMPRESS == (GlobalServerMsg)data[0])
            {
                byte nRecvPrior = 0;
                int  nRecvCount = 0;

                for (int i = 1; i < size; ++i)
                {
                    if ((0xEE == data[i]) && (0xEE == nRecvPrior))
                    {
                        nRecvCount--;
                        if (nRecvCount > 0)
                        {
                            HandleMessage(m_pBuffer_Batch, nRecvCount);
                        }
                        nRecvPrior = 0;
                        nRecvCount = 0;
                        continue;
                    }
                    else if ((0 == data[i]) && (0xEE == nRecvPrior))
                    {
                    }
                    else
                    {
                        if (nRecvCount < m_pBuffer_Batch.Length)
                        {
                            m_pBuffer_Batch[nRecvCount++] = data[i];
                        }
                        else
                        {
                            //     出错了
                        }
                    }
                    nRecvPrior = data[i];
                }
                return;
            }
            if (m_bSimpleProtocal)
            {
                InnerSimpleProtocal(ref data, size);
            }
            //LogSystem.Log( "Receive msg id = " , protocolId );
            //根据不同的协议ID进行消息分发
            ExcuteEvent(protocolId, data, size);
        }