private bool InnerParsePropValue(LoadArchive loadAr, int type, ref Var key) { switch (type) { case OuterDataType.OUTER_TYPE_BYTE: { int value = 0; if (!loadAr.ReadInt8(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_WORD: { int value = 0; if (!loadAr.ReadInt16(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_DWORD: { int value = 0; if (!loadAr.ReadInt32(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_QWORD: { long value = 0; if (!loadAr.ReadInt64(ref value)) { return(false); } key.SetInt64(value); } break; case OuterDataType.OUTER_TYPE_FLOAT: { float value = 0.0f; if (!loadAr.ReadFloat(ref value)) { return(false); } key.SetFloat(value); } break; case OuterDataType.OUTER_TYPE_DOUBLE: { double value = 0.0; if (!loadAr.ReadDouble(ref value)) { return(false); } key.SetDouble(value); } break; case OuterDataType.OUTER_TYPE_STRING: { string value = string.Empty; if (!loadAr.ReadString(ref value)) { return(false); } key.SetString(value); } break; case OuterDataType.OUTER_TYPE_WIDESTR: { string value = string.Empty; if (!loadAr.ReadWideStr(ref value)) { return(false); } key.SetWideStr(value); } break; case OuterDataType.OUTER_TYPE_OBJECT: { ObjectID value = ObjectID.zero; if (!loadAr.ReadObject(ref value)) { return(false); } key.SetObject(value); } break; default: return(false); } return(true); }
//读取数据 public static bool ReadData(ref LoadArchive loadAr, int nDataType, ref object obj) { switch (nDataType) { case OuterDataType.OUTER_TYPE_UNKNOWN: { LogSystem.LogError("Tools::ReadData nDataType error"); return(false); } // break; case OuterDataType.OUTER_TYPE_BYTE: { int value = 0; if (!loadAr.ReadInt8(ref value)) { LogSystem.LogError("Read OUTER_TYPE_BYTE error"); } } break; case OuterDataType.OUTER_TYPE_WORD: { int value = 0; if (!loadAr.ReadInt16(ref value)) { LogSystem.LogError("Read OUTER_TYPE_WORD error"); } } break; case OuterDataType.OUTER_TYPE_DWORD: { int value = 0; if (!loadAr.ReadInt32(ref value)) { LogSystem.LogError("Read OUTER_TYPE_DWORD error"); } } break; case OuterDataType.OUTER_TYPE_QWORD: { long value = 0; if (!loadAr.ReadInt64(ref value)) { LogSystem.LogError("Read OUTER_TYPE_QWORD error"); } } break; case OuterDataType.OUTER_TYPE_FLOAT: { float value = 0.0f; if (!loadAr.ReadFloat(ref value)) { LogSystem.LogError("Read OUTER_TYPE_FLOAT error"); } } break; case OuterDataType.OUTER_TYPE_DOUBLE: { double value = 0.0f; if (!loadAr.ReadDouble(ref value)) { LogSystem.LogError("Read OUTER_TYPE_DOUBLE error"); } } break; case OuterDataType.OUTER_TYPE_STRING: { string value = string.Empty; if (!loadAr.ReadString(ref value)) { LogSystem.LogError("Read OUTER_TYPE_STRING error"); } } break; case OuterDataType.OUTER_TYPE_WIDESTR: { string value = string.Empty; if (!loadAr.ReadWideStr(ref value)) { LogSystem.LogError("Read OUTER_TYPE_WIDESTR error"); } } break; case OuterDataType.OUTER_TYPE_OBJECT: { ObjectID value = ObjectID.zero; if (!loadAr.ReadObject(ref value)) { LogSystem.LogError("Read OUTER_TYPE_WIDESTR error"); } } break; default: LogSystem.LogError("unkwon data type"); return(false); } return(true); }
public bool RecvRecordRow(ref GameRecord rec, int index, ref LoadArchive ar, int row, int count) { try { if (rec == null || ar == null) { //Log.Trace("rec or ar is null"); return(false); } if (row < 0 || count < 0) { //Log.Trace("row or count < 0"); return(false); } if (!mRecordTable.ContainsKey(index)) { //Log.Trace("record table doesn't contain index:" + index.ToString()); return(false); } int col_count = mRecordTable[index].nCols; Var key = new Var(); for (int i = row; i < (row + count); i++) { if (!rec.InsertRow(i)) { //Log.Trace("InsertRow failed row =" + i.ToString()); return(false); } for (int c = 0; c < col_count; c++) { int nColType = mRecordTable[index].ColTypes[c]; switch (nColType) { case OuterDataType.OUTER_TYPE_BYTE: { int value = 0; if (!ar.ReadInt8(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_WORD: { int value = 0; if (!ar.ReadInt16(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_DWORD: { int value = 0; if (!ar.ReadInt32(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_QWORD: { long value = 0; if (!ar.ReadInt64(ref value)) { return(false); } key.SetInt64(value); } break; case OuterDataType.OUTER_TYPE_FLOAT: { float value = 0.0f; if (!ar.ReadFloat(ref value)) { return(false); } key.SetFloat(value); } break; case OuterDataType.OUTER_TYPE_DOUBLE: { double value = 0.0; if (!ar.ReadDouble(ref value)) { return(false); } key.SetDouble(value); } break; case OuterDataType.OUTER_TYPE_STRING: { string value = ""; if (!ar.ReadString(ref value)) { return(false); } key.SetString(value); } break; case OuterDataType.OUTER_TYPE_WIDESTR: { string value = ""; if (!ar.ReadWideStr(ref value)) { return(false); } key.SetWideStr(value); } break; case OuterDataType.OUTER_TYPE_OBJECT: { ObjectID value = new ObjectID(); if (!ar.ReadObject(ref value)) { return(false); } key.SetObject(value); } break; default: //Log.Trace("type error" + rec.GetName()); return(false); }//end switch if (!rec.SetValue(i, c, key)) { //Log.Trace("set value failed record name :" + rec.GetName()); return(false); } } //end(int c = 0; } //end for(int i = row } catch (Exception ex) { Log.TraceExcep(ref ex); return(false); } return(true); }
public bool RecvRecordGrid(ref GameRecord rec, int isViewObj, int nIdent, int nSerial, int index, ref LoadArchive loadAr, int count) { try { Var key = new Var(); for (int i = 0; i < count; i++) { int row = 0; int col = 0; if (!loadAr.ReadInt16(ref row)) { return(false); } if (!loadAr.ReadInt8(ref col)) { return(false); } if (col >= mRecordTable[index].nCols) { //Log.Trace("col error"); return(false); } switch (mRecordTable[index].ColTypes[col]) { case OuterDataType.OUTER_TYPE_BYTE: { int value = 0; if (!loadAr.ReadInt8(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_WORD: { int value = 0; if (!loadAr.ReadInt16(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_DWORD: { int value = 0; if (!loadAr.ReadInt32(ref value)) { return(false); } key.SetInt(value); } break; case OuterDataType.OUTER_TYPE_QWORD: { long value = 0; if (!loadAr.ReadInt64(ref value)) { return(false); } key.SetInt64(value); } break; case OuterDataType.OUTER_TYPE_FLOAT: { float value = 0.0f; if (!loadAr.ReadFloat(ref value)) { return(false); } key.SetFloat(value); } break; case OuterDataType.OUTER_TYPE_DOUBLE: { double value = 0.0; if (!loadAr.ReadDouble(ref value)) { return(false); } key.SetDouble(value); } break; case OuterDataType.OUTER_TYPE_STRING: { string value = ""; if (!loadAr.ReadString(ref value)) { return(false); } key.SetString(value); } break; case OuterDataType.OUTER_TYPE_WIDESTR: { string value = ""; if (!loadAr.ReadWideStr(ref value)) { return(false); } key.SetWideStr(value); } break; case OuterDataType.OUTER_TYPE_OBJECT: { ObjectID value = new ObjectID(); if (!loadAr.ReadObject(ref value)) { return(false); } key.SetObject(value); } break; default: //Log.Trace("unknown type record name " + rec.GetName()); return(false); }//end switch if (!rec.SetValue(row, col, key)) { //Log.Trace("set value error recname " + rec.GetName()); return(false); } if (isViewObj == 0) { string ident = nIdent.ToString() + "-" + nSerial.ToString(); VarList argList = new VarList(); argList.AddString(ident); argList.AddString(rec.GetName()); argList.AddInt(row); argList.AddInt(col); if (!Excute_CallBack("on_record_single_grid", argList)) { //Log.Trace("does not RegistCallBack on_record_single_grid"); } }//end if (isViewObj == 0) else if (isViewObj == 3) { string view_ident = nIdent.ToString(); VarList argList = new VarList(); argList.AddString(view_ident); argList.AddString(rec.GetName()); argList.AddInt(row); argList.AddInt(col); if (!Excute_CallBack("on_view_record_single_grid", argList)) { //Log.Trace("does not RegistCallBack on_view_record_single_grid"); } }//end if (isViewObj == 3) else if (isViewObj == 1) { string view_ident = nIdent.ToString(); string item_ident = nSerial.ToString(); VarList argList = new VarList(); argList.AddString(view_ident); argList.AddString(item_ident); argList.AddString(rec.GetName()); argList.AddInt(row); argList.AddInt(col); if (!Excute_CallBack("on_viewobj_record_single_grid", argList)) { //Log.Trace("does not RegistCallBack on_viewobj_record_single_grid"); } }//end if (isViewObj == 1) else if (isViewObj == 2) { VarList argList = new VarList(); argList.AddString(rec.GetName()); argList.AddInt(row); argList.AddInt(col); if (!Excute_CallBack("on_scene_record_single_grid", argList)) { //Log.Trace("does not RegistCallBack on_scene_record_single_grid"); } } //end if (isViewObj == 2) } // end for (int i = 0; i < count; i ++ ) } catch (System.Exception ex) { Log.TraceExcep(ref ex); return(false); } return(true); }
//读取数据 public static bool ReadData(ref LoadArchive loadAr, int nDataType, ref object obj) { switch (nDataType) { case OuterDataType.OUTER_TYPE_UNKNOWN: { //Log.TraceError("Tools::ReadData nDataType error"); return(false); } // break; case OuterDataType.OUTER_TYPE_BYTE: { int value = 0; if (!loadAr.ReadInt8(ref value)) { //Log.TraceError("Read OUTER_TYPE_BYTE error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + value + "]"); } break; case OuterDataType.OUTER_TYPE_WORD: { int value = 0; if (!loadAr.ReadInt16(ref value)) { //Log.TraceError("Read OUTER_TYPE_WORD error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + value + "]"); } break; case OuterDataType.OUTER_TYPE_DWORD: { int value = 0; if (!loadAr.ReadInt32(ref value)) { //Log.TraceError("Read OUTER_TYPE_DWORD error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + value + "]"); } break; case OuterDataType.OUTER_TYPE_QWORD: { long value = 0; if (!loadAr.ReadInt64(ref value)) { //Log.TraceError("Read OUTER_TYPE_QWORD error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + value + "]"); } break; case OuterDataType.OUTER_TYPE_FLOAT: { float value = 0.0f; if (!loadAr.ReadFloat(ref value)) { //Log.TraceError("Read OUTER_TYPE_FLOAT error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + value + "]"); } break; case OuterDataType.OUTER_TYPE_DOUBLE: { double value = 0.0f; if (!loadAr.ReadDouble(ref value)) { //Log.TraceError("Read OUTER_TYPE_DOUBLE error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + value + "]"); } break; case OuterDataType.OUTER_TYPE_STRING: { string value = ""; if (!loadAr.ReadString(ref value)) { //Log.TraceError("Read OUTER_TYPE_STRING error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + value + "]"); } break; case OuterDataType.OUTER_TYPE_WIDESTR: { string value = ""; if (!loadAr.ReadWideStr(ref value)) { //Log.TraceError("Read OUTER_TYPE_WIDESTR error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + value + "]"); } break; case OuterDataType.OUTER_TYPE_OBJECT: { ObjectID value = new ObjectID(); if (!loadAr.ReadObject(ref value)) { //Log.TraceError("Read OUTER_TYPE_WIDESTR error"); } // //Log.Trace("Read prop name = [" + propItem.getPropName() + "]" // + "prop value = [" + objId.m_nIdent + "." + objId.m_nSerial+"]"); } break; default: //Log.TraceError("unkwon data type"); return(false); } return(true); }
public void HandleMessage(byte[] data, int size) { if (data.Length == 0 || 0 == size) { Log.TraceError("Error, HandleMessage data is 0 "); return; } //byte[] byteTemp = new byte[size]; //System.Array.Copy(data, 0, byteTemp, 0, size); //init LoadArchive //LoadArchive loadAr = new LoadArchive(byteTemp, 0, byteTemp.Length); //LoadArchive loadAr = new LoadArchive(data, 0, size); int protocolId = data[0]; /*int protocolId = 0; * bool bRet = loadAr.ReadInt8(ref protocolId); * if (!bRet) * { * //Log.Trace("SocketReceiveHandle::HandleMessage parse get protocol id failed!"); * return; * }*/ //if (protocolId == GlobalServerMsg.SERVER_IDLE) //{ // //不处理 // return; //} /* * LoadArchive loadAr = new LoadArchive(data, 0, data.Length); * loadAr.Seek(1); * * int nArgNum = 0; * loadAr.ReadInt16(ref nArgNum); * int nType = 0; * loadAr.ReadInt8(ref nType); * int value = 0; * loadAr.ReadInt32(ref value); * * if (value.Equals(1401)) * { * loadAr.ReadInt8(ref nType); * int type = 0; * loadAr.ReadInt32(ref type); * if (type.Equals(1)) * { * Log.Trace("Receive msg id = " + value); * } * } */ ExcuteEvent(protocolId, data); if (protocolId.Equals(GlobalServerMsg.SERVER_CP_CUSTOM)) { byte[] content = new byte[data.Length - 1]; System.Array.Copy(data, 1, content, 0, content.Length); byte[] contentBytes = QuickLZ.decompress(content); byte[] dataTemp = new byte[contentBytes.Length + 1]; System.Array.Copy(data, 0, dataTemp, 0, 1); //拷贝消息id System.Array.Copy(contentBytes, 0, dataTemp, 1, contentBytes.Length); //拷贝解压后消息体(除去消息头) data = dataTemp; } if (protocolId.Equals(GlobalServerMsg.SERVER_CUSTOM) || protocolId.Equals(GlobalServerMsg.SERVER_CP_CUSTOM)) { LoadArchive loadAr = new LoadArchive(data, 0, data.Length); loadAr.Seek(1); int nArgNum = 0; loadAr.ReadInt16(ref nArgNum); int nType = 0; loadAr.ReadInt8(ref nType); loadAr.ReadInt32(ref protocolId); } CustomSystem.Instance.dispacthEvent(0, protocolId); }
private bool InnerParsePropValue(LoadArchive loadAr, int type, ref VarList.VarData key) { switch (type) { case OuterDataType.OUTER_TYPE_BYTE: { int value = 0; if (!loadAr.ReadInt8(ref value)) { return(false); } key.nType = VarType.Int; key.Data = value; } break; case OuterDataType.OUTER_TYPE_WORD: { int value = 0; if (!loadAr.ReadInt16(ref value)) { return(false); } key.nType = VarType.Int; key.Data = value; } break; case OuterDataType.OUTER_TYPE_DWORD: { int value = 0; if (!loadAr.ReadInt32(ref value)) { return(false); } key.nType = VarType.Int; key.Data = value; } break; case OuterDataType.OUTER_TYPE_QWORD: { long value = 0; if (!loadAr.ReadInt64(ref value)) { return(false); } key.nType = VarType.Int64; key.Data = value; } break; case OuterDataType.OUTER_TYPE_FLOAT: { float value = 0.0f; if (!loadAr.ReadFloat(ref value)) { return(false); } key.nType = VarType.Float; key.Data = value; } break; case OuterDataType.OUTER_TYPE_DOUBLE: { double value = 0.0; if (!loadAr.ReadDouble(ref value)) { return(false); } key.nType = VarType.Double; key.Data = value;; } break; case OuterDataType.OUTER_TYPE_STRING: { string value = ""; if (!loadAr.ReadString(ref value)) { return(false); } key.nType = VarType.String; key.Data = value; } break; case OuterDataType.OUTER_TYPE_WIDESTR: { string value = ""; if (!loadAr.ReadWideStr(ref value)) { return(false); } key.nType = VarType.WideStr; key.Data = value; } break; case OuterDataType.OUTER_TYPE_OBJECT: { ObjectID value = new ObjectID(); if (!loadAr.ReadObject(ref value)) { return(false); } key.nType = VarType.Object; key.Data = value; } break; default: return(false); } return(true); }