public static void Trigger(string strTriggerName, AsyncTrigger.OnTrigger onTrigger, params object[] args) { if (!AsyncTrigger.mTriggers.ContainsKey(strTriggerName)) { return; } AsyncTrigger.TriggerInfo triggerInfo = AsyncTrigger.mTriggers[strTriggerName]; triggerInfo.iTriggerCount--; if (triggerInfo.iTriggerCount > 0) { return; } if (onTrigger != null) { try { onTrigger(args); } catch (Exception ex) { LogSystem.LogError(new object[] { ex.ToString() }); } } AsyncTrigger.mTriggers.Remove(strTriggerName); }
public static void OnTriggerTimer(params object[] args) { if (args == null || args.Length < 2) { return; } string text = args[0] as string; if (!AsyncTrigger.mTriggers.ContainsKey(text)) { return; } AsyncTrigger.TriggerInfo triggerInfo = AsyncTrigger.mTriggers[text]; if (triggerInfo.onTrigger != null) { try { triggerInfo.onTrigger(new object[] { text }); } catch (Exception ex) { LogSystem.LogError(new object[] { ex.ToString() }); } } AsyncTrigger.mTriggers.Remove(text); TimerManager.DestroyTimer(text); }
public bool QueryPropObject(string strPropName, ref ObjectID oResult) { if (strPropName == null) { return(false); } try { if (!mPropSet.ContainsKey(strPropName)) { return(false); } GameProperty prop = mPropSet[strPropName]; Var propValue = prop.getPropValue(); if (propValue.Type != VarType.Object) { return(false); } oResult = propValue.GetObject(); return(true); } catch (Exception ex) { LogSystem.LogError("Error, exception ", ex.ToString()); return(false); } }
/* @brief:表数据单行数据改变消息入口点 * @param: args 该事件参数列表 * @return void */ public static void on_record_grid(VarList args) { string strRecordName = args.GetString(1); int iCount = args.GetInt(2); List <IRecord> iRecord; if (mRecords.TryGetValue(strRecordName, out iRecord) && iRecord != null) { for (int i = 0; i < iRecord.Count; i++) { if (iRecord[i] != null) { try { iRecord[i].on_record_grid(strRecordName, iCount); } catch (System.Exception e) { LogSystem.LogError(e.ToString()); } } } } }
public bool GetBool(int row, int col, ref bool bValue) { if (row < 0 || col < 0 || row >= GetRowCount() || col >= GetColcount()) { LogSystem.Log("Error,GameRecord.GetValue row or col out of range:"); return(false); } try { VarList rowItem = rowSet[row]; if (colTypes[col] == VarType.Int) { bValue = rowItem.GetBool(col); return(false); } } catch (Exception ex) { LogSystem.LogError(ex.ToString()); return(false); } return(false); }
/// <summary> /// 修改对象AOI列表 /// </summary> /// <param name="role"></param> /// <param name="target"></param> public static void MotifyObjectAoi(IObject self, IObject target) { if (self == null || self.mAOIList == null || target == null || self == target) { return; } if (self.mAOIRange < 0.01) { LogSystem.LogError("RoleAOIRange less than 0.01"); return; } if (Vector3.Distance(self.mPosition, target.mPosition) <= self.mAOIRange && !target.mIsDead) { if (!self.mAOIList.Contains(target)) { self.mAOIList.Add(target); MotifyObjectAoi(target, self); } } else { if (self.mAOIList.Contains(target)) { self.mAOIList.Remove(target); } } }
public static bool WriteLocalAsset(string strPath, byte[] bytes) { FileInfo fileInfo = new FileInfo(strPath); if (fileInfo.Exists && !AssetFileUtils.DeleteAsset(strPath)) { return(false); } try { if (!fileInfo.Exists) { Directory.CreateDirectory(fileInfo.DirectoryName); } AssetFileUtils.WriteFile(strPath, bytes); return(true); } catch (Exception ex) { LogSystem.LogError(new object[] { "WriteLocalAsset", ex.ToString() }); } return(false); }
void PrepareMiniGame() { //If the current game index is greater than the length of the MiniGame array, then the player has successfully completed the game. if (currentMiniGameIndex_ >= MiniGames_.Length) { GameSuccessful(); return; } //Gets in here once you click start at teh beginning of the game GameObject create_mini_game = GameObject.Instantiate(MiniGames_[currentMiniGameIndex_]); //MiniGames_ stores an array of all the games if (create_mini_game != null) { currentMiniGame_ = create_mini_game.GetComponent <MiniGameBase> (); if (currentMiniGame_ == null) { LogSystem.LogError("Mini game " + create_mini_game.name + " error, can't find the class <MiniGameBase>"); return; } } usingCard_ = UsingCard.NONE; Messenger <string, string> .Broadcast(UIMsg.SetGameInfo.ToString(), currentMiniGame_.GameName_, currentMiniGame_.GameDescription_, MessengerMode.DONT_REQUIRE_LISTENER); Messenger.Broadcast(GameEvent.SetupMiniGame.ToString(), MessengerMode.DONT_REQUIRE_LISTENER); EnableRayCast_ = true; //test //MiniGameStart (); }
//发送请求移动消息 //public bool RequestMove(int mode, int arg_num, float[] args, string info) public bool RequestMove(ref VarList args, ref VarList ret) { try { if (args.GetCount() < 1) { ret.AddBool(false); return(false); } int mode = args.GetInt(0); int arg_num = args.GetCount() - 1; StoreArchive ar = StoreArchive.Load(m_buffer, m_buffer.Length); ar.WriteInt8(GlobalClineMsgId.CLIENT_REQUEST_MOVE);//消息ID ar.WriteInt8(mode); ar.WriteInt16(arg_num); for (int i = 0; i < arg_num; i++) { float value = args.GetFloat(1 + i); ar.WriteFloat(value); } return(m_sender.Send(ar.GetData(), ar.GetLength())); } catch (System.Exception ex) { LogSystem.LogError(ex); return(false); } }
public bool ChooseRole(string role_name) { if (role_name == null) { LogSystem.LogError("Role Name Is Empty!"); return(false); } if (0 == role_name.Length) { LogSystem.Log("sendChooseRole packet role name is empty!"); return(false); } byte[] name = new byte[ServerInfo.ROLENAME_MAX_LENGTH * 2 + 1]; Array.Copy(System.Text.Encoding.Default.GetBytes(role_name), name, role_name.Length); StoreArchive ar = StoreArchive.Load(m_buffer, m_buffer.Length); ar.WriteInt8(GlobalClineMsgId.CLIENT_CHOOSE_ROLE);//消息ID //unsigned short wsName[OUTER_OBJNAME_LENGTH + 1]; // 名称 //unsigned char nVerify[16]; // 校验码 //char strInfo[1]; ar.WriteUnicodeLen(role_name, (ServerInfo.ROLENAME_MAX_LENGTH + 1) * 2);//玩家名 byte[] verify = new byte[16]; fxVerify.GetChooseRoleVerify(role_name, ref verify); ar.WriteUserDataNoLen(verify); //检验码 ar.WriteInt8(0); //附加信息 return(m_sender.Send(ar.GetData(), ar.GetLength())); }
public bool DeleteRole(string role_name) { if (role_name == null) { LogSystem.LogError("Role Name Is Empty!"); return(false); } if (0 == role_name.Length) { LogSystem.Log("DeleteRole role name is empty!"); return(false); } byte[] name = new byte[ServerInfo.ROLENAME_MAX_LENGTH * 2 + 1]; Array.Copy(System.Text.Encoding.Default.GetBytes(role_name), name, role_name.Length); StoreArchive ar = StoreArchive.Load(m_buffer, m_buffer.Length); ar.WriteInt8(GlobalClineMsgId.CLIENT_DELETE_ROLE);//消息ID //unsigned short wsName[OUTER_OBJNAME_LENGTH + 1]; // 名称 ar.WriteUnicodeLen(role_name, (ServerInfo.ROLENAME_MAX_LENGTH + 1) * 2);//玩家名 return(m_sender.Send(ar.GetData(), ar.GetLength())); }
/// <summary> /// 写入资源包操作 /// </summary> /// <param name="strPath">路径</param> /// <param name="bytes">包数据</param> /// <returns>成败</returns> public static bool WriteLocalAsset(string strPath, byte[] bytes) { FileInfo t = new FileInfo(strPath); if (t.Exists) { if (!DeleteAsset(strPath)) { return(false); } } try { if (!t.Exists) { Directory.CreateDirectory(t.DirectoryName); } WriteFile(strPath, bytes); return(true); } catch (System.Exception ex) { LogSystem.LogError("WriteLocalAsset", ex.ToString()); } return(false); }
static void OnNetBlockOrClose() { try { //Debug.Log("OnNetBlockOrClose"); gConnectCount = 0; WorldStage.mbReConnected = true; //启动断线重连,重新发送登录消息 Game game = Game.Instance; if (game != null) { game.mGameSock.Disconnect(); game.mGameSock.InitUserSock(); ConnectStage.RegistCallback(false); LoginStage.RegistCallback(false); WorldStage.RegistCallback(false); ///第一次连接失败,添加心跳开始持续一分钟连接12次,依然没有连上认为断开 ConnectStage.ConnecToMember(mstrServer, miPort, mstrUser, mstrPsd, mstrValidateString, 2); //Debug.Log("第一次重连"); TimerManager.AddTimerRepeat("OnNetBlockTimer", 5.0f, OnNetBlockTimer); LogSystem.LogWarning("First block connect try"); //SystemWaitPanel.Start(99999999); } } catch (System.Exception ex) { LogSystem.LogError("Game::OnNetBlockOrClose:", ex.ToString()); } }
/// <summary> /// 网络阻色 /// </summary> /// <param name="args"></param> public static void on_connect_block(VarList args) { try { Game game = Game.Instance; if (game == null) { //Debug.Log("on_connect_block: game is null"); return; } if (!game.mbEnterGame) { //Debug.Log("不在游戏中不进行断线重连"); return; } //测试用,看看是否是因为这里面没有断线重连 if (!mbConnected || isChangeRole) { //Debug.Log("----------------- mbConnected =" + mbConnected); //Debug.Log("----------------- isChangeRole =" + isChangeRole); //return; } ///被顶下线不重连 if (LoginStage.miErrorCode == 21006) { //Debug.Log("被顶下线不重连"); return; } if (mbTryingConnect) { //Debug.Log("尝试重连中。这里不重连"); return; } mbTryingConnect = true; if (mbLoginSuccess && ObjectManager.mRole != null) { mbNeedReConnect = true; if (game.mGameSock == null) { //Debug.Log("Error!! ConnectState::on_connect_fail (game or game.mGameSock) is null"); LogSystem.LogError("Error!! ConnectState::on_connect_fail (game or game.mGameSock) is null"); return; } //网络标志连接中 if (!game.mbPaused) { OnNetBlockOrClose(); } } } catch (System.Exception ex) { LogSystem.LogError("Game::on_connect_block:", ex.ToString()); } }
/* @brief: 视窗对象属性变化回调 * @param: args 回调参数 * @return void */ public static void on_view_object_property_change(VarList args) { string strViewID = args.GetString(0); string strObjID = args.GetString(1); string strName = args.GetString(2); List <IDataView> iDataView; if (mViews.TryGetValue(strViewID, out iDataView) && iDataView != null) { for (int i = 0; i < iDataView.Count; i++) { if (iDataView[i] != null) { try { iDataView[i].on_view_object_property_change(strViewID, strObjID, strName); } catch (System.Exception e) { LogSystem.LogError(e.ToString()); } } } } }
/// <summary> /// 延时心跳触发时间回调 /// </summary> /// <param name="args"></param> static public void OnTriggerTimer(params object[] args) { if (args == null || args.Length < 2) { return; } ///检查是否包含触发节点 string strTriggerName = args[0] as string; if (!mTriggers.ContainsKey(strTriggerName)) { return; } ///触发用户接口 TriggerInfo tInfo = mTriggers[strTriggerName]; if (tInfo.onTrigger != null) { try { tInfo.onTrigger(strTriggerName); } catch (System.Exception ex) { LogSystem.LogError(ex.ToString()); } } ///删除触发器和心跳 mTriggers.Remove(strTriggerName); TimerManager.Destroy(strTriggerName); }
/* @brief: 接收服务器自定义消息,并按注册代理分发 * @param: args 服务器自定义消息参数列表 * @return void */ public static void on_custom(VarList args) { int iCustomCmd = args.GetInt(1); if (mCustoms.ContainsKey(iCustomCmd)) { List <OnCustom> list = mCustoms[iCustomCmd]; if (list != null) { for (int i = 0; i < list.Count; i++) { if (list[i] != null) { try { list[i](args); } catch (System.Exception e) { LogSystem.LogError(e.ToString()); } } } } } }
/// <summary> /// /// </summary> public void SwitchGame() { if (currentMiniGame_ != null) { currentMiniGame_.DestroyGame(); currentMiniGame_ = null; } int rnd_index = Random.Range(0, listUnusedGames_.Count); MiniGames_[currentMiniGameIndex_] = listUnusedGames_[rnd_index]; GameObject create_mini_game = GameObject.Instantiate(listUnusedGames_[rnd_index]); if (create_mini_game != null) { currentMiniGame_ = create_mini_game.GetComponent <MiniGameBase>(); if (currentMiniGame_ == null) { LogSystem.LogError("Mini game " + create_mini_game.name + " error, can't find the class <MiniGameBase>"); return; } } usingCard_ = UsingCard.NONE; Messenger <string, string> .Broadcast(UIMsg.SetGameInfo.ToString(), currentMiniGame_.GameName_, currentMiniGame_.GameDescription_, MessengerMode.DONT_REQUIRE_LISTENER); Messenger.Broadcast(GameEvent.SetupMiniGame.ToString(), MessengerMode.DONT_REQUIRE_LISTENER); }
/// <summary> /// 重新选择角色成功后,清理数据 /// </summary> public void ReChooseRoleClear() { //断线重新选择角色成功,将重新选择角色标识符 制为false 恢复到正常状态 // ConnectStage.isChangeRole = false; try { // GameSceneManager.on_exit_scene(new SysUtils.VarList()); // //GameSceneManager.Clear(); // WorldStage.RegistCallback(); } catch (System.Exception ex) { LogSystem.LogError("ReChooseRole on_exit_scene catch error", ex.ToString()); } try { // GUIManager.DestroyAllView(); // TimerManager.ClearTimer(); } catch (System.Exception ex) { LogSystem.LogError("rechooseRole DestroyAllView catch error", ex.ToString()); } // Instance.Get<PlayerHeadControl>().InitPanel(); }
public bool GetInt64(int row, int col, ref long lValue) { try { if (row >= GetRowCount() || col >= GetColcount()) { lValue = 0; return(false); } VarList row_value = (VarList)rowSet[row]; if (row_value.GetType(col) != VarType.Int64) { lValue = 0; return(false); } lValue = row_value.GetInt64(col); } catch (Exception ex) { lValue = 0; LogSystem.LogError(ex.ToString()); return(false); } return(true); }
/// <summary> /// 触发同步 /// </summary> /// <param name="strTriggerName"></param> /// <param name="onTrigger"></param> /// <param name="args"></param> static public void Trigger(string strTriggerName, OnTrigger onTrigger, params object[] args) { if (!mTriggers.ContainsKey(strTriggerName)) { return; } ///检查是否可以触发 TriggerInfo tInfo = mTriggers[strTriggerName]; tInfo.iTriggerCount--; if (tInfo.iTriggerCount > 0) { return; } ///触发用户接口 if (onTrigger != null) { try { onTrigger(args); } catch (System.Exception ex) { LogSystem.LogError(ex.ToString()); } } ///清除触发器 mTriggers.Remove(strTriggerName); }
/* @brief: 分发表格清除消息 * @param:回调参数列表 * @return void */ public static void onTableClear(VarList args) { int index = 2; string tableName = args.GetString(index++); List <ITable> iTabel; if (mRecords.TryGetValue(tableName, out iTabel) && iTabel != null && mRecordCols.ContainsKey(tableName)) { for (int i = 0; i < iTabel.Count; i++) { if (iTabel[i] != null) { try { iTabel[i].on_table_clear(tableName, args, index); } catch (System.Exception e) { LogSystem.LogError(e.ToString()); } } } } }
public void RequestServerState() { string ipInfo = "127.0.0.1";// Config.GetUpdaterConfig("StateServerPath", "Value"); if (string.IsNullOrEmpty(ipInfo)) { //状态服务器地址没有配置/ LogSystem.LogError("RequestServerState --> ipinfo not in config!"); return; } string[] ipinfoStrs = UtilTools.Split(ipInfo, ':'); if (ipinfoStrs.Length < 3) { LogSystem.LogError("RequestServerState -->ipinfo config Error"); return; } ip = ipinfoStrs[0]; port = UtilTools.IntParse(ipinfoStrs[1]); issuerId = UtilTools.IntParse(ipinfoStrs[2]); ServerStateSock sock = new ServerStateSock(OnTextSockConnected, OnTextSockConnectFailed, OnTextSockRecieveData); if (sock != null) { sock.Connect(ip, port); } dataIsReady = false; TimerManager.AddTimer("StateReqOverTime", 10f, StateReqListener); //#endif }
/// <summary> /// 设置连接器参数,检查是否触发 /// </summary> /// <param name="iIndex"></param> /// <param name="o"></param> public void SetLinkerArgs(int iIndex, object o) { if (iIndex >= 0 && iIndex < mUserArgs.Length) { mUserArgs[iIndex] = o; } ///检查是否触发 if (CheckArgsFull()) { try { if (mLinkerFun != null) { mLinkerFun(this, mUserArgs); } } catch (System.Exception ex) { LogSystem.LogError(ex.ToString()); } ///回收所有触发器 UserDelegateTriggle.CollectTriggle(mTriggles); } }
/* @brief: 分发表格删除指定内容消息 * @param:回调参数列表 * @return void */ public static void onTableDelete(VarList args) { int index = 2; string tableName = args.GetString(index++); int row = args.GetInt(index++); List <ITable> iTabel; if (mRecords.TryGetValue(tableName, out iTabel) && iTabel != null && mRecordCols.ContainsKey(tableName)) { int iCols = mRecordCols[tableName]; for (int i = 0; i < iTabel.Count; i++) { if (iTabel[i] != null) { try { iTabel[i].on_table_delete(tableName, args, row, (args.GetCount() - index) / iCols, iCols, index); } catch (System.Exception e) { LogSystem.LogError(e.ToString()); } } } } }
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); } }
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 void InitUserSock() { if (m_sock != null) { try { if (m_sock.Connected) { m_sock.Disconnect(false); //m_sock.Close(); } } catch (System.Exception ex) { LogSystem.LogError(ex.ToString()); } } m_sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_scoket = new UserSock(m_sockcall, m_sock); if (m_gameSender == null) { m_gameSender = new GameSender(); } m_gameSender.SetSocket(ref m_scoket); }
/// <summary> /// 发送 /// </summary> /// <param name="ar"></param> public static void Send(IAsyncResult ar) { SendContext self = (SendContext)ar.AsyncState; UserSock uSock = self.uUserSock; if (uSock.m_State == SockState.Idle) { return; } int size = 0; try { size = uSock.m_Socket.EndSend(ar); } catch (SocketException e) { uSock.SetSockError(e.ErrorCode, e.ToString()); LogSystem.LogError(e.ToString()); } catch (Exception ex) { LogSystem.LogError(ex.ToString()); } finally { } uSock.StopSend(self.sendBuff, size); uSock.PushSendContext(self); }
//在玩家表格条目中增加一条 (索引,表格结构信息) 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); }