private bool InnerRecvProperty(GameObj obj, LoadArchive loadAr, int count, bool change) { if (obj == null) { return(false); } try { Var key = Var.zero; for (int i = 0; i < count; i++) { int index = 0; if (!loadAr.ReadInt16(ref index)) { return(false); } if (index >= mPropertyTable.Count) { return(false); } PropData propData = GetPropDataByIndex(index); propData.nCount = propData.nCount + 1; if (!InnerParsePropValue(loadAr, propData.nType, ref key)) { return(false); } if (!obj.UpdateProperty(ref propData.strName, key)) { return(false); } if (change) { VarList argList = VarList.GetVarList(); argList.AddString(obj.GetIdent()); argList.AddString(propData.strName); Excute_CallBack("on_object_property_change", argList); argList.Collect(); } } } catch (System.Exception ex) { LogSystem.Log("GameReceiver.InnerRecvViewProperty() Exception:", ex.ToString()); } return(true); }
public int OnSockConnected(UserSock sock, string addr, int port) { LogSystem.Log("OnSockConnected"); m_gamesock.SetConnected(true); if (null != m_gamesock.m_lgsockcall) { m_gamesock.m_lgsockcall.on_connected(addr, port); return(1); } else { if (m_gamesock != null) { VarList args = VarList.GetVarList(); args.AddString(addr); args.AddInt(port); m_gamesock.Excute_CallBack("on_connected", args); args.Collect(); return(1); } else { LogSystem.LogError("Error, OnSockConnected gamesock is null"); } return(0); } }
public int OnSockConnectFail(UserSock sock, string addr, int port) { LogSystem.Log("OnSockConnectFail"); PromptManager.Instance.ShowPromptUI(XmlManager.Instance.GetCommonText("System0001")); m_gamesock.SetConnected(false); if (null != m_gamesock.m_lgsockcall) { m_gamesock.m_lgsockcall.on_connect_failed(addr, port); return(1); } else { if (m_gamesock != null) { VarList args = VarList.GetVarList(); args.AddString(addr); args.AddInt(port); m_gamesock.Excute_CallBack("on_connect_fail", args); args.Collect(); return(1); } else { LogSystem.LogError("Error, OnSockConnectFail gamesock is null"); } return(0); } }
// string public bool SetValue(int row, int col, string result) { if (row >= GetRowCount() || col >= GetColcount() || row < 0 || col < 0) { return(false); } VarList rowItem = rowSet[row]; if (rowItem == null) { return(false); } if (col < rowItem.GetCount()) { rowItem.SetString(col, result); } else { rowItem.AddString(result); } return(true); }
public int OnSockConnectFail(UserSock sock, string addr, int port) { //Log.Trace("OnSockConnectFail"); if (null != m_gamesock.m_lgsockcall) { m_gamesock.m_lgsockcall.on_connect_failed(addr, port); return(1); } else { if (m_gamesock != null) { VarList args = new VarList(); args.AddString(addr); args.AddInt(port); m_gamesock.Excute_CallBack("on_connect_fail", args); return(1); } else { //Log.TraceError("Error, OnSockConnectFail gamesock is null"); } return(0); } }
public void GetObjectList(ref VarList result) { if (result == null) { return; } foreach (string strKey in mObjects.Keys) { result.AddString(strKey); } }
public void GetRecordList(ref VarList args, ref VarList result) { foreach (KeyValuePair <string, GameRecord> kvp in mRecordSet) { string name = kvp.Key; if ((name != null) && (name.Length != 0)) { result.AddString(name); } } }
public void GetPropList(ref VarList args, ref VarList result) { foreach (KeyValuePair <string, GameProperty> kvp in mPropSet) { string name = kvp.Key; if ((name != null) && (name.Length != 0)) { result.AddString(name); } } }
/// <summary> /// 赋值VarList /// </summary> /// <param name="args"></param> /// <param name="index"></param> /// <param name="newList"></param> public static void CopyVarList(ref VarList args, ref VarList newList, int start, int count) { int index = start; for (; index < args.GetCount() && count > 0; index++, count--) { int type = args.GetType(index); switch (type) { case VarType.Bool: newList.AddBool(args.GetBool(index)); break; case VarType.Int: newList.AddInt(args.GetInt(index)); break; case VarType.String: newList.AddString(args.GetString(index)); break; case VarType.WideStr: newList.AddWideStr(args.GetWideStr(index)); break; case VarType.Object: newList.AddObject(args.GetObject(index)); break; case VarType.Float: newList.AddFloat(args.GetFloat(index)); break; case VarType.Double: newList.AddDouble(args.GetDouble(index)); break; case VarType.Int64: newList.AddInt64(args.GetInt64(index)); break; } } }
public void GetRoleInfo(ref VarList args, ref VarList ret) { try { if (mRoles == null || mRoles.Count == 0) { return; } if (args == null || ret == null) { return; } if (args.GetCount() == 0) { return; } if (args.GetType(0) != VarType.Int) { return; } int nIndex = args.GetInt(0); if (nIndex >= mRoles.Count) { return; } VarList paraList = mRoles[nIndex].paraList; for (int i = 0; i < paraList.GetCount(); i++) { switch (paraList.GetType(i)) { case VarType.Bool: { ret.AddBool(paraList.GetBool(i)); } break; case VarType.Int: { ret.AddInt(paraList.GetInt(i)); } break; case VarType.Int64: { ret.AddInt64(paraList.GetInt64(i)); } break; case VarType.Float: { ret.AddFloat(paraList.GetFloat(i)); } break; case VarType.Double: { ret.AddDouble(paraList.GetDouble(i)); } break; case VarType.String: { ret.AddString(paraList.GetString(i)); } break; case VarType.WideStr: { ret.AddWideStr(paraList.GetWideStr(i)); } break; case VarType.Object: { ret.AddObject(paraList.GetObject(i)); } break; default: return; } } } catch (Exception ex) { //Log.Trace("GameReceiver.GetRoleInfo Exception:" + ex.ToString()); } return; }
public bool SetValue(int row, int col, Var result) { try { if (row >= GetRowCount() || col >= GetColcount() || row < 0 || col < 0) { return(false); } if (null == result) { return(false); } VarList rowItem = rowSet[row]; if (rowItem == null) { return(false); } if (col > rowItem.GetCount()) { //Log.Trace("col error col=" + col.ToString()); return(false); } switch (result.Type) { case VarType.Int: { if (col < rowItem.GetCount()) { rowItem.SetInt(col, result.GetInt()); } else { rowItem.AddInt(result.GetInt()); } } break; case VarType.Int64: { if (col < rowItem.GetCount()) { rowItem.SetInt64(col, result.GetInt64()); } else { rowItem.AddInt64(result.GetInt64()); } } break; case VarType.Float: { if (col < rowItem.GetCount()) { rowItem.SetFloat(col, result.GetFloat()); } else { rowItem.AddFloat(result.GetFloat()); } } break; case VarType.Double: { if (col < rowItem.GetCount()) { rowItem.SetDouble(col, result.GetDouble()); } else { rowItem.AddDouble(result.GetDouble()); } } break; case VarType.String: { if (col < rowItem.GetCount()) { rowItem.SetString(col, result.GetString()); } else { rowItem.AddString(result.GetString()); } } break; case VarType.WideStr: { if (col < rowItem.GetCount()) { rowItem.SetWideStr(col, result.GetWideStr()); } else { rowItem.AddWideStr(result.GetWideStr()); } } break; case VarType.Object: { if (col < rowItem.GetCount()) { rowItem.SetObject(col, result.GetObject()); } else { rowItem.AddObject(result.GetObject()); } } break; default: //Log.Trace("typer error type=" + result.Type.ToString()); return(false); }//end switch //rowSet[row] = rowItem; //int nCount = rowItem.GetCount(); return(true); } catch (Exception ex) { Log.TraceExcep(ref ex); return(false); } }
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 void AddObjectArgs(ref VarList args, ref object o) { System.Type itype = o.GetType(); if (itype == typeof(bool)) { args.AddBool((bool)o); } else if (itype == typeof(int)) { args.AddInt((int)o); } else if (itype == typeof(long)) { args.AddInt64((long)o); } else if (itype == typeof(float)) { args.AddFloat((float)o); } else if (itype == typeof(double)) { args.AddDouble((double)o); } else if (itype == typeof(ObjectID)) { args.AddObject((ObjectID)o); } else if (itype == typeof(string)) { args.AddString((string)o); } else if (itype == typeof(byte[])) { args.AddUserData((byte[])o); } else if (itype == typeof(WideString)) { args.AddWideStr(((WideString)o).mstrContent); } else if (itype == typeof(VarList)) { int iCount = ((VarList)o).GetCount(); for (int j = 0; j < iCount; j++) { switch (((VarList)o).GetType(j)) { case VarType.Bool: args.AddBool(((VarList)o).GetBool(j)); break; case VarType.Int: args.AddInt(((VarList)o).GetInt(j)); break; case VarType.Int64: args.AddInt64(((VarList)o).GetInt64(j)); break; case VarType.Float: args.AddFloat(((VarList)o).GetFloat(j)); break; case VarType.Double: args.AddDouble(((VarList)o).GetDouble(j)); break; case VarType.String: args.AddString(((VarList)o).GetString(j)); break; case VarType.WideStr: args.AddWideStr(((VarList)o).GetWideStr(j)); break; case VarType.Object: args.AddObject(((VarList)o).GetObject(j)); break; case VarType.UserData: args.AddUserData(((VarList)o).GetUserData(j)); break; } } } }
//发送客户端自定义消息,请保留此功能,谢谢! public static bool SendCustomGM(string content) { if (mGameSender == null) { return(false); } VarList args = VarList.GetVarList(); string[] split = content.Split(' '); int len = split.Length; if (len % 2 == 0) { for (int i = 0; i < len; ++i) { switch (split[i]) { case "BOOL": ++i; args.AddBool(Convert.ToBoolean(split[i])); break; case "INT": ++i; args.AddInt(Convert.ToInt32(split[i])); break; case "INT64": ++i; args.AddInt64(Convert.ToInt64(split[i])); break; case "FLOAT": ++i; args.AddFloat(Convert.ToSingle(split[i])); break; case "DOUBLE": ++i; args.AddDouble(Convert.ToDouble(split[i])); break; case "STRING": ++i; args.AddString(split[i]); break; case "WIDESTR": ++i; args.AddWideStr(split[i]); break; } } } if (mGameSender.Custom(ref args)) { args.Collect(); return(true); } args.Collect(); return(false); }
public bool RecieveData(byte[] data, int iSize) { if (iSize > maxBufLength - miIndex) { return(false); } Array.Copy(data, 0, mBuffer, miIndex, iSize); if (miIndex >= 4) { //消息头已经收到,解析出消息头/ messageLength = BitConverter.ToInt32(mBuffer, 0); } else { //头还没有接接收完/ messageLength = -1; } miIndex += iSize; if (miIndex >= messageLength) { int compressFlag = BitConverter.ToInt32(mBuffer, 4); byte[] bufferBody = new byte[mBuffer.Length - 8]; Array.Copy(mBuffer, 8, bufferBody, 0, bufferBody.Length); byte[] bodys = null; if (compressFlag > 0) { bodys = ServerStateQuickLZ.decompress(bufferBody); } else { bodys = new byte[mBuffer.Length - 8]; try { Array.Copy(mBuffer, 8, bodys, 0, bodys.Length); } catch (Exception e) { UnityEngine.Debug.LogError(e.ToString()); } } if (bodys.Length > 0) { //解析消息 int m_nCurPosi = 0; int Head1_0 = 0; int Head1_1 = 0; int Head2_0 = 0; int Head2_1 = 0; m_nCurPosi = 0; Head1_0 = BitConverter.ToInt32(bodys, m_nCurPosi); m_nCurPosi += 4; Head1_1 = BitConverter.ToInt32(bodys, m_nCurPosi); m_nCurPosi += 4; Head2_0 = BitConverter.ToInt32(bodys, m_nCurPosi); m_nCurPosi += 4; Head2_1 = BitConverter.ToInt32(bodys, m_nCurPosi); m_nCurPosi += 4; int count = BitConverter.ToInt32(bodys, m_nCurPosi); m_nCurPosi += 4; VarList args = VarList.GetVarList(); args.AddInt(count); int byteSize = bodys.Length; for (int i = 0; i < count; i++) { int len = 0; for (int c = 0; c < byteSize - m_nCurPosi - 1; c++) { try { char v = '\0'; if (m_nCurPosi + c < bodys.Length) { v = BitConverter.ToChar(bodys, m_nCurPosi + c); } if (v == '\0' || bodys[m_nCurPosi + c] == 0) { break; } } catch (Exception e) { UnityEngine.Debug.LogError(e.ToString()); } len++; } if (len > 0) { byte[] dddd = new byte[len]; Array.Copy(bodys, m_nCurPosi, dddd, 0, len); //byte[] des = Encoding.Convert(Encoding.UTF8, System.Text.Encoding.Default, dddd); string str = System.Text.Encoding.UTF8.GetString(dddd); args.AddString(str); } m_nCurPosi += len + 1;//1表示'\0' } if (monRecieve != null) { monRecieve(this, ref args); } return(true); } else { return(false); } } return(false); }
private bool InnerRecvProperty(GameObj obj, LoadArchive loadAr, int count, bool change) { VarList.VarData key = new VarList.VarData(); for (int i = 0; i < count; i++) { int index = 0; if (!loadAr.ReadInt16(ref index)) { return(false); } if (index >= mPropertyTable.Count) { return(false); } PropData propData = GetPropDataByIndex(index); if (propData == null) { return(false); } propData.nCount = propData.nCount + 1; if (!InnerParsePropValue(loadAr, propData.nType, ref key)) { return(false); } if (!obj.UpdateProperty(ref propData.strName, key)) { return(false); } if (change) { VarList argList = new VarList(); argList.AddObject(obj.GetIdent()); argList.AddString(propData.strName); Excute_CallBack("on_object_property_change", argList); } } return(true); }