public bool AddMsgVarList(StoreArchive ar, VarList args, int beg, int end) { try { for (int i = beg; i < end; ++i) { switch (args.GetType(i)) { case VarType.Int: ar.WriteInt8(VarType.Int); ar.WriteInt32(args.GetInt(i)); break; case VarType.Int64: ar.WriteInt8(VarType.Int64); ar.WriteInt64(args.GetInt64(i)); break; case VarType.Float: ar.WriteInt8(VarType.Float); ar.WriteFloat(args.GetFloat(i)); break; case VarType.Double: ar.WriteInt8(VarType.Double); ar.WriteDouble(args.GetDouble(i)); break; case VarType.String: ar.WriteInt8(VarType.String); ar.WriteString(args.GetString(i)); break; case VarType.WideStr: ar.WriteInt8(VarType.WideStr); ar.WriteWideStr(args.GetWideStr(i)); break; case VarType.Object: ar.WriteInt8(VarType.Object); ar.WriteObject(args.GetObject(i)); break; default: break; } } } catch (Exception ex) { LogSystem.LogError(ex.ToString()); return(false); } return(true); }
/// <summary> /// 服务器定位消息 /// </summary> /// <param name="data"></param> /// <param name="len"></param> /// <returns></returns> private int proc_server_location(ref Byte[] data, int len) { if (len < 16) { return(len); } LoadArchive arLoad = LoadArchive.Load(data, len); // Byte[] buffer = new Byte[1024]; StoreArchive arStore = StoreArchive.Load(m_pBuffer_SP, 4096); uint nMsgType = 0; arLoad.ReadUInt8(ref nMsgType); arStore.WriteUInt8(nMsgType); ObjectID objectId = ObjectID.zero; arLoad.ReadObject(ref objectId); arStore.WriteObject(objectId); int x = 0; arLoad.ReadInt16(ref x); arStore.WriteFloat(x / 100.0f); int y = 0; arLoad.ReadInt16(ref y); arStore.WriteFloat(y / 100.0f); int z = 0; arLoad.ReadInt16(ref z); arStore.WriteFloat(z / 100.0f); int orient = 0; arLoad.ReadInt16(ref orient); arStore.WriteFloat(orient / 100.0f); data = arStore.GetData(); return(arStore.GetLength()); }
public bool Select(string object_ident, int func_id) { if (object_ident == null) { //Log.TraceError("GameSender Select object_ident is null"); return(false); } ObjectID objID = ObjectID.FromString(object_ident); StoreArchive ar = new StoreArchive(m_buffer, m_buffer.Length); ar.WriteInt8(GlobalClineMsgId.CLIENT_SELECT);//消息ID //unsigned char nVerify[4]; // 校验码 //int nSerial; // 消息序列号 //outer_object_t ObjectId; // 对象标识 //int nFunctionId; // 功能号为0表示执行缺省功能 //byte[] message = TypeConvert.encode(m_buffer,ar.GetLength()); byte[] data = new byte[256]; int index = 0; //序号,名字加入校验 MsgEncode.WriteInt16(ref data, ref index, (uint)MsgEncode.Instance.Serial); MsgEncode.WriteInt16(ref data, ref index, (uint)MsgEncode.Instance.MsgSerial); MsgEncode.WriteInt32(ref data, ref index, (uint)func_id); MsgEncode.WriteObject(ref data, ref index, objID); byte[] verify = MsgEncode.Instance.Encode(data, index, 4); ar.WriteUserDataNoLen(verify); //检验码 ar.WriteInt32(MsgEncode.Instance.MsgSerial); //消息序列号 ar.WriteObject(objID); //对象标识 ar.WriteInt32(func_id); return(m_sender.Send(ar.GetData(), ar.GetLength())); }
public bool Select(string object_ident, int func_id) { if (object_ident == null) { LogSystem.LogError("GameSender Select object_ident is null"); return(false); } if (0 == object_ident.Length) { LogSystem.LogError("GameSender Select object_ident is empty"); return(false); } StoreArchive ar = StoreArchive.Load(m_buffer, m_buffer.Length); ar.WriteInt8(GlobalClineMsgId.CLIENT_SELECT);//消息ID //unsigned char nVerify[16]; // 校验码 //int nSerial; // 消息序列号 //outer_object_t ObjectId; // 对象标识 //int nFunctionId; // 功能号为0表示执行缺省功能 //byte[] message = TypeConvert.encode(m_buffer,ar.GetLength()); ObjectID obj = ObjectID.FromString(object_ident); byte[] verify = new byte[16]; fxVerify.GetSelectVerify(func_id, (int)(obj.m_nSerial), mCustomIndex, (int)(obj.m_nIdent), ref verify); ar.WriteUserDataNoLen(verify); //检验码 ar.WriteInt32(mCustomIndex++); //消息序列号 ar.WriteObject(obj); //对象标识 ar.WriteInt32(func_id); return(m_sender.Send(ar.GetData(), ar.GetLength())); }
bool AddMsgVarList(ref StoreArchive storeAr, ref VarList args, int beg, int end) { try { for (int i = beg; i < end; i++) { switch (args.GetType(i)) { case VarType.Int: { storeAr.WriteInt8(VarType.Int); storeAr.WriteInt32(args.GetInt(i)); } break; case VarType.Int64: { storeAr.WriteInt8(VarType.Int64); storeAr.WriteInt64(args.GetInt64(i)); } break; case VarType.Float: { storeAr.WriteInt8(VarType.Float); storeAr.WriteFloat(args.GetFloat(i)); } break; case VarType.Double: { storeAr.WriteInt8(VarType.Double); storeAr.WriteDouble(args.GetDouble(i)); } break; case VarType.String: { storeAr.WriteInt8(VarType.String); storeAr.WriteString(args.GetString(i)); } break; case VarType.WideStr: { storeAr.WriteInt8(VarType.WideStr); storeAr.WriteWideStr(args.GetWideStr(i)); } break; case VarType.Object: { storeAr.WriteInt8(VarType.Object); storeAr.WriteObject(args.GetObject(i)); } break; default: //Log.Trace("unkown data type"); break; } //end switch } //end for } catch (Exception ex) { //Log.Trace("Exception:" + ex.ToString()); return(false); }//end try catch return(true); }
/// <summary> /// 服务器所有目标点移动 /// </summary> /// <param name="data"></param> /// <param name="len"></param> /// <returns></returns> private int proc_server_all_dest(ref Byte[] data, int len) { LoadArchive arLoad = LoadArchive.Load(data, len); // Byte[] buffer = new Byte[1024]; StoreArchive arStore = StoreArchive.Load(m_pBuffer_SP, 4096); uint nMsgType = 0; arLoad.ReadUInt8(ref nMsgType); arStore.WriteUInt8(nMsgType); uint nCount = 0; arLoad.ReadUInt16(ref nCount); arStore.WriteUInt16(nCount); if (nCount > 50) { LogSystem.Log("proc_server_all_dest"); return(len); } for (int i = 0; i < nCount; ++i) { ObjectID objectId = ObjectID.zero; arLoad.ReadObject(ref objectId); arStore.WriteObject(objectId); int x = 0; arLoad.ReadInt16(ref x); arStore.WriteFloat(x / 100.0f); int y = 0; arLoad.ReadInt16(ref y); arStore.WriteFloat(y / 100.0f); int z = 0; arLoad.ReadInt16(ref z); arStore.WriteFloat(z / 100.0f); int orient = 0; arLoad.ReadInt16(ref orient); arStore.WriteFloat(orient / 100.0f); int moveSpeed = 0; arLoad.ReadInt16(ref moveSpeed); arStore.WriteFloat(moveSpeed / 100.0f); int rotateSpeed = 0; arLoad.ReadInt16(ref rotateSpeed); arStore.WriteFloat(rotateSpeed / 100.0f); int jumpSpeed = 0; arLoad.ReadInt16(ref jumpSpeed); arStore.WriteFloat(jumpSpeed / 100.0f); int gravity = 0; arLoad.ReadInt16(ref gravity); arStore.WriteFloat(gravity / 100.0f); int mode = 0; arLoad.ReadInt32(ref mode); arStore.WriteInt32(mode); } data = arStore.GetData(); return(arStore.GetLength()); }
/// <summary> /// 服务器移动消息 /// </summary> /// <param name="data"></param> /// <param name="len"></param> /// <returns></returns> private int proc_server_moving(ref Byte[] data, int len) { if (len < 28) { return(len); } LoadArchive arLoad = LoadArchive.Load(data, len); // Byte[] buffer = new Byte[1024]; StoreArchive arStore = StoreArchive.Load(m_pBuffer_SP, 4096); uint nMsgType = 0; arLoad.ReadUInt8(ref nMsgType); arStore.WriteUInt8(nMsgType); ObjectID objectId = ObjectID.zero; arLoad.ReadObject(ref objectId); arStore.WriteObject(objectId); int x = 0; arLoad.ReadInt16(ref x); arStore.WriteFloat(x / 100.0f); int y = 0; arLoad.ReadInt16(ref y); arStore.WriteFloat(y / 100.0f); int z = 0; arLoad.ReadInt16(ref z); arStore.WriteFloat(z / 100.0f); int orient = 0; arLoad.ReadInt16(ref orient); arStore.WriteFloat(orient / 100.0f); int moveSpeed = 0; arLoad.ReadInt16(ref moveSpeed); arStore.WriteFloat(moveSpeed / 100.0f); int rotateSpeed = 0; arLoad.ReadInt16(ref rotateSpeed); arStore.WriteFloat(rotateSpeed / 100.0f); int jumpSpeed = 0; arLoad.ReadInt16(ref jumpSpeed); arStore.WriteFloat(jumpSpeed / 100.0f); int gravity = 0; arLoad.ReadInt16(ref gravity); arStore.WriteFloat(gravity / 100.0f); int mode = 0; arLoad.ReadInt32(ref mode); arStore.WriteInt32(mode); data = arStore.GetData(); return(arStore.GetLength()); }