//响应RoomServer玩家重新连接进入房间的反馈消息 internal void OnReplyReconnectUser(ulong userGuid, int roomID, bool isSuccess) { UserInfo user = LobbyServer.Instance.DataProcessScheduler.GetUserInfo(userGuid); if (user == null) { return; } if (isSuccess) { user.CurrentState = UserState.Room; RoomInfo room = m_LobbyInfo.GetRoomByID(roomID); if (null != room) { RoomServerInfo svrInfo; if (m_LobbyInfo.RoomServerInfos.TryGetValue(room.RoomServerName, out svrInfo)) { if (null != svrInfo) { JsonMessageWithGuid startGameResultMsg = new JsonMessageWithGuid(JsonMessageID.StartGameResult); startGameResultMsg.m_Guid = user.Guid; ArkCrossEngineMessage.Msg_LC_StartGameResult protoData = new ArkCrossEngineMessage.Msg_LC_StartGameResult(); protoData.server_ip = svrInfo.ServerIp; protoData.server_port = svrInfo.ServerPort; protoData.key = user.Key; protoData.hero_id = user.HeroId; protoData.camp_id = user.CampId; protoData.scene_type = room.SceneType; protoData.match_key = user.CurrentBattleInfo.MatchKey; protoData.result = (int)GeneralOperationResult.LC_Succeed; startGameResultMsg.m_ProtoData = protoData; JsonMessageDispatcher.SendDcoreMessage(user.NodeName, startGameResultMsg); //重新进入房间成功 LogSys.Log(LOG_TYPE.INFO, "User Reconnected RoomServer Success ! , guid:{0}", userGuid); } } } } else { user.CurrentState = UserState.Online; LogSys.Log(LOG_TYPE.INFO, "User Reconnected RoomServer Failed ! , guid:{0}", userGuid); } }
public bool VerifyNotMovingPosition(float x, float z, float maxEnabledDistSqr) { bool ret = true; if (m_LastSampleTime > 0) { Vector3 pos = new Vector3(x, 0, z); float distSqr = Geometry.DistanceSquare(pos, m_LastClientPosition); if (distSqr > maxEnabledDistSqr) { ret = false; LogSys.Log(LOG_TYPE.ERROR, "VerifyNoMoveData user:{0}({1},{2},{3}) x:{4} z:{5} sx:{6} sz:{7}", RoleId, GetKey(), Guid, Name, x, z, m_LastClientPosition.X, m_LastClientPosition.Z); } } return(ret); }
internal bool VerifyNotMovingPosition(float x, float z, float maxEnabledDistSqr) { bool ret = true; if (m_LastSampleTime > 0) { Vector3 pos = new Vector3(x, 0, z); float distSqr = Geometry.DistanceSquare(pos, m_LastClientPosition); if (distSqr > maxEnabledDistSqr) { ret = false; LogSys.Log(LOG_TYPE.ERROR, "VerifyNoMoveData user:{0} x:{1} z:{2} sx:{3} sz:{4}", RoleId, x, z, m_LastClientPosition.X, m_LastClientPosition.Z); } } return(ret); }
public void SendPeerMessage(RoomPeer peer, RoomMessageDefine id, object msg) { try { NetOutgoingMessage om = m_NetServer.CreateMessage(); om.Write(Serialize.Encode(msg, (int)id)); if (null != peer.GetConnection()) { NetSendResult res = m_NetServer.SendMessage(om, peer.GetConnection(), NetDeliveryMethod.ReliableOrdered, 0); if (res == NetSendResult.Dropped) { LogSys.Log(LOG_TYPE.ERROR, "SendPeerMessage {0} failed:dropped, User:{1}({2})", msg.ToString(), peer.Guid, peer.GetKey()); } } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
internal void HandleArenaStartChallenge(ulong guid, ulong target_guid) { LogSys.Log(LOG_TYPE.DEBUG, "---got start challenge result msg! id=" + guid); UserInfo user = LobbyServer.Instance.DataProcessScheduler.GetUserInfo(guid); if (user == null) { return; } ArenaInfo target_arena_info = m_ArenaSystem.GetArenaInfoById(target_guid); JsonMessageWithGuid resultMsg = new JsonMessageWithGuid(JsonMessageID.ArenaStartChallengeResult); resultMsg.m_Guid = guid; ArkCrossEngineMessage.Msg_LC_ArenaStartCallengeResult protoData = new ArkCrossEngineMessage.Msg_LC_ArenaStartCallengeResult(); protoData.m_TargetGuid = target_guid; protoData.m_Sign = new Random().Next(); if (target_arena_info != null && target_arena_info.IsNeedUpdate(user)) { target_arena_info.UpdateArenaInfo(user); } bool start_ret = m_ArenaSystem.StartChallenge(guid, target_guid, protoData.m_Sign); if (target_arena_info == null) { protoData.m_ResultCode = (int)GeneralOperationResult.LC_Failure_Arena_NotFindTarget; } else if (!start_ret) { protoData.m_ResultCode = (int)m_ArenaSystem.ErrorCode; } else { user.UpdateGuideFlag((int)MatchSceneEnum.Arena); user.CurrentState = UserState.Pve; protoData.m_ResultCode = (int)GeneralOperationResult.LC_Succeed; ChallengeInfo challenge = m_ArenaSystem.GetDoingChallengeInfo(guid); if (challenge != null && challenge.Target != null) { float coefficent = ChallengeChecker.CalcPvpCoefficient(user.Level, target_arena_info.Level); int total_hp = ChallengeChecker.CalcPlayerHp(target_arena_info, coefficent); challenge.Target.TotalHp = total_hp; //LogSys.Log(LOG_TYPE.DEBUG, "challenge target totalhp={0}", total_hp); } } resultMsg.m_ProtoData = protoData; JsonMessageDispatcher.SendDcoreMessage(user.NodeName, resultMsg); LogSys.Log(LOG_TYPE.DEBUG, "---send start challenge result msg! id=" + guid); }
protected override void OnTick() { try { long curTime = TimeUtility.GetLocalMilliseconds(); if (m_LastTickTime != 0) { long elapsedTickTime = curTime - m_LastTickTime; if (elapsedTickTime > c_WarningTickTime) { LogSys.Log(LOG_TYPE.MONITOR, "DataCacheSystem Tick:{0}", elapsedTickTime); } } m_LastTickTime = curTime; if (m_LastLogTime + 60000 < curTime) { m_LastLogTime = curTime; DebugPoolCount((string msg) => { LogSys.Log(LOG_TYPE.INFO, "DataCacheSystem.ActionQueue {0}", msg); }); m_LoadActionQueue.DebugPoolCount((string msg) => { LogSys.Log(LOG_TYPE.INFO, "DataCacheSystem.LoadActionQueue {0}", msg); }); m_SaveActionQueue.DebugPoolCount((string msg) => { LogSys.Log(LOG_TYPE.INFO, "DataCacheSystem.SaveActionQueue {0}", msg); }); LogSys.Log(LOG_TYPE.MONITOR, "DataCacheSystem.ActionQueue Current Action {0}", this.CurActionNum); } if (curTime - m_LastCacheTickTime > c_CacheTickInterval) { m_InnerCacheSystem.Tick(); m_LastCacheTickTime = curTime; } m_LoadActionQueue.HandleActions(4096); m_SaveActionQueue.HandleActions(4096); PersistentSystem.Instance.Tick(); } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "DataCacheSystem ERROR:{0} \n StackTrace:{1}", ex.Message, ex.StackTrace); if (ex.InnerException != null) { LogSys.Log(LOG_TYPE.ERROR, "DataCacheSystem INNER ERROR:{0} \n StackTrace:{1}", ex.InnerException.Message, ex.InnerException.StackTrace); } } }
internal void UpdateRoomServerInfo(RoomServerInfo info) { RoomServerInfo info_; if (!m_LobbyInfo.RoomServerInfos.TryGetValue(info.RoomServerName, out info_)) { m_LobbyInfo.RoomServerInfos.Add(info.RoomServerName, info); } else { info_.IdleRoomNum = info.IdleRoomNum; info_.UserNum = info.UserNum; info_.AllocedRoomNum = 0; } LogSys.Log(LOG_TYPE.DEBUG, "UpdateRoomServerInfo,name:{0},idle room num:{1},cur user num:{2}", info.RoomServerName, info.IdleRoomNum, info.UserNum); }
//=================================================================== //以下为与RoomServer之间的消息通信 //响应RoomServer发来的房间创建反馈消息 internal void OnReplyCreateBattleRoom(int roomId, bool isSuccess) { if (isSuccess) { m_LobbyInfo.StartBattleRoom(roomId); RoomInfo room = m_LobbyInfo.GetRoomByID(roomId); if (room == null) { return; } foreach (WeakReference info in room.Users.Values) { UserInfo user = info.Target as UserInfo; if (user != null) { user.CurrentState = UserState.Room; user.CurrentRoomID = roomId; } } } else { //玩家重新进入匹配队列 RoomInfo room = m_LobbyInfo.GetRoomByID(roomId); if (room == null) { return; } LogSys.Log(LOG_TYPE.DEBUG, "StartGameResult, failed from RoomServer:{0},room id:{1}", room.RoomServerName, room.RoomId); foreach (WeakReference info in room.Users.Values) { UserInfo user = info.Target as UserInfo; if (user != null) { user.CurrentState = UserState.Online; user.IsPrepared = false; LobbyServer.Instance.MatchFormThread.QueueAction(LobbyServer.Instance.MatchFormThread.RequestMatch, user.Guid, room.SceneType); } } m_LobbyInfo.StopBattleRoom(roomId); } }
private void LoadHandler(LNReq_Load msg, PBChannel channel, int handle, uint seq) { try { DataOperator.Instance.LoadActionQueue.QueueAction((MyAction <uint, string, MyAction <DSLoadResult, string, IMessage> >)DataOperator.Instance.Load, msg.DsMsgId, msg.Key, (ret, error, data) => { var reply = NLRep_Load.CreateBuilder(); reply.SetDsMsgId(msg.DsMsgId); reply.SetKey(msg.Key); if (ret == DSLoadResult.Success) { reply.SetResult(NLRep_Load.Types.LoadResult.Success); reply.SetData(ByteString.Unsafe.FromBytes(channel_.Encode(data))); } else if (ret == DSLoadResult.Undone) { reply.SetResult(NLRep_Load.Types.LoadResult.Undone); reply.SetData(ByteString.Unsafe.FromBytes(channel_.Encode(data))); } else if (ret == DSLoadResult.NotFound) { reply.SetResult(NLRep_Load.Types.LoadResult.NotFound); reply.SetError(error); } else { reply.SetResult(NLRep_Load.Types.LoadResult.Error); reply.SetError(error); } NLRep_Load replyData = reply.Build(); channel.Send(replyData); LogSys.Log(LOG_TYPE.INFO, "Load data finished. msgId:({0}) key:({1}) result:({2}) ", msg.DsMsgId, msg.Key, ret); }); } catch (Exception e) { var errorReply = NLRep_Load.CreateBuilder(); errorReply.SetResult(NLRep_Load.Types.LoadResult.Error); errorReply.SetError(e.Message); channel.Send(errorReply.Build()); LogSys.Log(LOG_TYPE.ERROR, "GMServer load data failed. msgId:({0}) key:({1}) seq:({2}) error:({3} detail:{4})", msg.DsMsgId, msg.Key, seq, e.Message, e.StackTrace); } }
private void OnMessage(uint seq, int source_handle, int dest_handle, IntPtr data, int len) { try { if (IsUnknownServer(source_handle)) { StringBuilder sb = new StringBuilder(256); if (CenterClientApi.TargetName(source_handle, sb, 256)) { string name = sb.ToString(); if (name.StartsWith("NodeJs")) { m_NodeHandles.Add(source_handle); } else if (name.StartsWith("RoomSvr")) { m_RoomSvrHandles.Add(source_handle); } else if (name.StartsWith("UserSvr")) { m_UserHandles.Add(source_handle); } } } byte[] bytes = new byte[len]; Marshal.Copy(data, bytes, 0, len); if (IsNode(source_handle)) { if (!m_WaitQuit) { m_UserProcessScheduler.DispatchJsonMessage(seq, source_handle, dest_handle, bytes); } } else if (IsUserServer(source_handle)) { DispatchUserMessage(source_handle, seq, bytes); } else if (IsRoomServer(source_handle)) { m_RoomProcessThread.QueueAction(m_RoomSvrChannel.Dispatch, source_handle, seq, bytes); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
internal static void Execute(object msg, User user) { Msg_CRC_StoryMessage target_msg = msg as Msg_CRC_StoryMessage; if (target_msg == null) { return; } Scene scene = user.OwnRoom.ActiveScene; if (scene != null) { try { //客户端发来的消息都加上前缀client,防止直接调用服务器端逻辑(服务器消息不能用client前缀!) string msgId = string.Format("client:{0}", target_msg.m_MsgId); ArrayList args = new ArrayList(); args.Add(user.RoleId); for (int i = 0; i < target_msg.m_Args.Count; i++) { switch (target_msg.m_Args[i].val_type) { case ArgType.NULL: //null args.Add(null); break; case ArgType.INT: //int args.Add(int.Parse(target_msg.m_Args[i].str_val)); break; case ArgType.FLOAT: //float args.Add(float.Parse(target_msg.m_Args[i].str_val)); break; default: //string args.Add(target_msg.m_Args[i].str_val); break; } } object[] objArgs = args.ToArray(); scene.StorySystem.SendMessage(msgId, objArgs); } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_StoryMessage throw exception:{0}\n{1}", ex.Message, ex.StackTrace); } } }
private static List <IMessage> ExecuteLoadSQL(Type tableType, string tableName, string statement, MessageDescriptor md) { List <IMessage> datas = new List <IMessage>(); Dictionary <string, ColumnInfo> columnInfos = GetColumnInfo(tableName); IBuilder builder = (IBuilder)tableType.InvokeMember( "CreateBuilder", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, null); try { MySqlCommand cmd = new MySqlCommand(statement, DBConn.MySqlConn); cmd.CommandType = CommandType.Text; using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { foreach (FieldDescriptor fd in md.Fields) { string col_name = fd.Name; string func_name = string.Format("Set{0}", fd.CSharpOptions.PropertyName); ColumnInfo ci = columnInfos[col_name]; object value = reader[col_name]; if (fd.FieldType == FieldType.Bytes) { value = ByteString.Unsafe.FromBytes((byte[])value); } builder.GetType().InvokeMember(func_name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod, null, builder, new object[] { value }); } datas.Add(builder.WeakBuild()); } return(datas); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Execute load SQL ERROR:{0}\n Stacktrace:{1} \n SQL statement:{2}\n", ex.Message, ex.StackTrace, statement); throw ex; } }
internal void QueueMessage(bool isGmTool, uint seq, int sourceHandle, int destHandle, byte[] data) { try { NodeMessageInfo info; if (!m_MsgPool.TryDequeue(out info)) { info = new NodeMessageInfo(); } info.IsGmTool = isGmTool; info.Seq = seq; info.SourceHandle = sourceHandle; info.DestHandle = destHandle; info.Data = data; m_MsgQueue.Enqueue(info); } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "NodeMessageThread.QueueMessage {0} {1} {2} {3} throw exception:{4}\n{5}", isGmTool, seq, sourceHandle, destHandle, ex.Message, ex.StackTrace); } }
private void PlayGame() { LogSys.Log(LOG_TYPE.ERROR, "PlayGame"); if (string.IsNullOrEmpty(m_UserId) == true) { return; } m_StringBuilder.Clear(); m_StringBuilder.Append(m_RoleList[0].RoleId); string str = m_StringBuilder.ToString(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str); SendBytes((int)TCPGameServerCmds.CMD_PLAY_GAME, bytes); }
private void OnNameHandleChanged(bool addOrUpdate, string name, int handle) { try { m_GmSvrChannel.OnUpdateNameHandle(addOrUpdate, name, handle); m_BridgeChannel.OnUpdateNameHandle(addOrUpdate, name, handle); m_StoreChannel.OnUpdateNameHandle(addOrUpdate, name, handle); if (!addOrUpdate) { m_NodeHandles.Remove(handle); m_RoomSvrHandles.Remove(handle); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
//响应RoomServer发来的房间内玩家掉线消息 internal void OnRoomUserQuit(int roomid, ulong guid, bool isBattleEnd) { UserInfo user = LobbyServer.Instance.DataProcessScheduler.GetUserInfo(guid); if (user != null) { if (isBattleEnd) { user.CurrentRoomID = 0; user.CurrentState = UserState.Room == user.CurrentState ? UserState.Online : user.CurrentState; } else { user.CurrentRoomID = roomid; } LogSys.Log(LOG_TYPE.INFO, "RoomServer User Quit , guid:{0} state:{1} isEnd:{2}", guid, user.CurrentState, isBattleEnd); } }
internal void SaveGuid(List <GuidInfo> guidList, int saveCount) { try { foreach (var guidinfo in guidList) { TableGuid dataGuid = new TableGuid(); dataGuid.GuidType = guidinfo.GuidType; dataGuid.GuidValue = (ulong)guidinfo.NextGuid; Msg_LD_Save msg = new Msg_LD_Save(); msg.MsgId = (int)DataEnum.TableGuid; msg.PrimaryKeys.Add(dataGuid.GuidType); msg.Data = DbDataSerializer.Encode(dataGuid); DispatchAction(SaveInternal, msg); } } catch (Exception e) { LogSys.Log(LOG_TYPE.ERROR, "DataCache Save ERROR:{0}, Stacktrace:{1}", e.Message, e.StackTrace); } }
internal void HandleArenaQueryRank(ulong guid, int handle) { JsonMessageWithGuid resultMsg = new JsonMessageWithGuid(JsonMessageID.ArenaQueryRankResult); resultMsg.m_Guid = guid; ArkCrossEngineMessage.Msg_LC_ArenaQueryRankResult protoData = new ArkCrossEngineMessage.Msg_LC_ArenaQueryRankResult(); ArenaInfo cur_info = m_ArenaSystem.GetArenaInfoById(guid); if (cur_info != null) { List<ArenaInfo> result = m_ArenaSystem.QueryRankList(cur_info.GetRank()); for (int i = 0; i < result.Count; i++) { protoData.RankMsg.Add(ArenaUtil.CreateArenaInfoMsg(result[i])); } } resultMsg.m_ProtoData = protoData; JsonMessageDispatcher.SendDcoreMessage(handle, resultMsg); LogSys.Log(LOG_TYPE.DEBUG, "send query rank list!"); }
private void RoleList() { if (string.IsNullOrEmpty(m_UserId) == true) { return; } LogSys.Log(LOG_TYPE.ERROR, "RoleList"); m_StringBuilder.Clear(); m_StringBuilder.Append(m_UserId) .Append(":") .Append(ZoneId.ToString()); string str = m_StringBuilder.ToString(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str); SendBytes((int)TCPGameServerCmds.CMD_ROLE_LIST, bytes); }
internal bool Init(int room_id, int scene_type, UserPool userpool, Connector conn) { LogSys.Log(LOG_TYPE.INFO, "[0] Room.Init {0} scene {1}", room_id, scene_type); cur_room_id_ = room_id; user_pool_ = userpool; connector_ = conn; can_close_time_ = 0; m_ActiveScene = m_ScenePool.NewScene(); LogSys.Log(LOG_TYPE.INFO, "[1] Room.Init {0} scene {1}", room_id, scene_type); m_ActiveScene.SetRoom(this); //场景数据加载由加载线程执行(注:场景没有加载完成,场景状态仍然是sleep,Scene.Tick不会有实际的动作) SceneLoadThread.Instance.QueueAction(m_ActiveScene.LoadData, scene_type); m_ActiveTime = TimeUtility.GetLocalMicroseconds(); CurrentState = RoomState.Active; m_CanFinish = false; LogSys.Log(LOG_TYPE.DEBUG, "Room Initialize: {0} Scene: {1}", room_id, scene_type); return(true); }
internal static int CalcPlayerHp(ArenaInfo info, float coefficent) { int result = 0; if (info == null) { return(result); } UserArenaAttr user_attr = CalcArenaTargetAttr(info); if (user_attr != null) { user_attr.HpMax = (int)(user_attr.HpMax * coefficent); result += user_attr.HpMax; LogSys.Log(LOG_TYPE.INFO, "--user hp=" + user_attr.HpMax); } return(result); }
//向DB中写入多条数据 internal static int BatchSaveItemsProc(int msgId, List <InnerCacheItem> cacheItemList, int dataVersion) { if (DataCacheConfig.IsPersistent) { try { foreach (var cacheItem in cacheItemList) { DataDML.Save(msgId, cacheItem.Valid, dataVersion, cacheItem.DataMessage); } LogSys.Log(LOG_TYPE.MONITOR, "BatchSaveItemsProc SUCCESS. MsgId:{0}, DataCount:{1}, DataVersion:{2}", msgId, cacheItemList.Count, dataVersion); } catch (Exception ex) { DBConn.Close(); LogSys.Log(LOG_TYPE.ERROR, "BatchSaveItemsProc ERROR. MsgId:{0}, Error:{1}\nStacktrace:{2}", msgId, ex.Message, ex.StackTrace); throw ex; } } return(cacheItemList.Count); }
public void DropUser(User user) { //向Lobby发送玩家掉线消息 Msg_RL_UserDrop uaqBuilder = new Msg_RL_UserDrop(); uaqBuilder.RoomId = RoomId; uaqBuilder.UserGuid = user.Guid; uaqBuilder.IsBattleEnd = false; m_Connector.SendMsgToLobby(uaqBuilder); user.LastNotifyUserDropTime = TimeUtility.GetLocalMilliseconds(); //控制状态改为掉线 user.UserControlState = (int)UserControlState.UserDropped; if (null != user.Info) { // user.Info.Suicide(); } LogSys.Log(LOG_TYPE.DEBUG, "Room {0} User {1}({2}) dropped.", RoomId, user.Guid, user.GetKey()); }
protected override void OnTick() { long curTime = TimeUtility.GetServerMilliseconds(); if (m_LastLogTime + 60000 < curTime) { m_LastLogTime = curTime; DebugPoolCount((string msg) => { LogSys.Log(LOG_TYPE.INFO, "GmServerThread.ActionQueue {0}", msg); }); } const int c_MaxIterationPerTick = 100; if (IsLobbyFull() || GetTotalQueueingCount() <= 0) { //大厅已经满或者没有排队的玩家,多休息1秒 System.Threading.Thread.Sleep(1000); } else { DataProcessScheduler dataProcess = LobbyServer.Instance.DataProcessScheduler; for (int i = 0; i < c_MaxIterationPerTick; ++i) { foreach (KeyValuePair <int, Queue <string> > pair in m_QueueingAccounts) { int serverId = pair.Key; Queue <string> queue = pair.Value; if (queue.Count > 0 && CanEnter(serverId)) { string accountKey = queue.Dequeue(); IncEnterCount(serverId); LoginInfo info; if (m_QueueingInfos.TryRemove(accountKey, out info) && info.LoginServerId == serverId) { dataProcess.DispatchAction(dataProcess.DoAccountLoginWithoutQueueing, accountKey, info.AccountId, info.LoginServerId, info.ClientGameVersion, info.ClientLoginIp, info.UniqueIdentifier, info.System, info.ChannelId, info.NodeName); ++i; } } } } } }
internal void DSPLoadUser(ulong userGuid, string accountId, string nickname) { string key = userGuid.ToString(); Msg_LD_Load msg = new Msg_LD_Load(); msg.MsgId = (int)DataEnum.TableUserInfo; msg.PrimaryKeys.Add(key); Msg_LD_SingleLoadRequest reqUser = new Msg_LD_SingleLoadRequest(); reqUser.MsgId = (int)DataEnum.TableUserInfo; reqUser.LoadType = Msg_LD_SingleLoadRequest.LoadTypeEnum.LoadSingle; reqUser.Keys.Add(key); msg.LoadRequests.Add(reqUser); Msg_LD_SingleLoadRequest reqItem = new Msg_LD_SingleLoadRequest(); reqItem.MsgId = (int)DataEnum.TableItemInfo; reqItem.LoadType = Msg_LD_SingleLoadRequest.LoadTypeEnum.LoadMulti; reqItem.Keys.Add(key); msg.LoadRequests.Add(reqItem); Msg_LD_SingleLoadRequest reqFriend = new Msg_LD_SingleLoadRequest(); reqFriend.MsgId = (int)DataEnum.TableFriendInfo; reqFriend.LoadType = Msg_LD_SingleLoadRequest.LoadTypeEnum.LoadMulti; reqFriend.Keys.Add(key); msg.LoadRequests.Add(reqFriend); RequestLoad(msg, (ret) => { KeyString primaryKey = KeyString.Wrap(ret.PrimaryKeys); if (Msg_DL_LoadResult.ErrorNoEnum.Success == ret.ErrorNo) { LogSys.Log(LOG_TYPE.INFO, "DataCache Load Success: Msg:{0}, Key:{1}", "DSP_User", primaryKey); } else if (Msg_DL_LoadResult.ErrorNoEnum.NotFound == ret.ErrorNo) { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "DataCache Load NotFound: Msg:{0}, Key:{1}", "DSP_User", primaryKey); } else { LogSys.Log(LOG_TYPE.ERROR, "DataCache Load Failed: Msg:{0}, Key:{1}, ERROR:{2}", "DSP_User", primaryKey, ret.ErrorInfo); } UserProcessScheduler dataProcessScheduler = UserServer.Instance.UserProcessScheduler; dataProcessScheduler.DefaultUserThread.QueueAction(dataProcessScheduler.DSPLoadUserCallback, ret, accountId, nickname); }); }
protected override void OnTick() { long curTime = TimeUtility.GetLocalMilliseconds(); if (m_LastTickTime + c_TickInterval < curTime) { m_LastTickTime = curTime; DBConn.KeepConnection(); try { MySqlConnection conn = DBConn.MySqlConn; using (MySqlCommand cmd = new MySqlCommand("select * from GowStar where 1=2", conn)) { cmd.ExecuteNonQuery(); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.INFO, "DbThread.Tick keep connection exception:{0}\n{1}", ex.Message, ex.StackTrace); } } }
internal void SaveDeletedMail(List <TableMailInfoWrap> mailList, int saveCount) { try { foreach (var mailInfo in mailList) { if (!mailInfo.Deleted) { continue; } Msg_LD_Save msg = new Msg_LD_Save(); msg.MsgId = (int)DataEnum.TableMailInfo; msg.PrimaryKeys.Add(mailInfo.Guid.ToString()); msg.Data = null; DispatchAction(SaveInternal, msg); } } catch (Exception e) { LogSys.Log(LOG_TYPE.ERROR, "DataCache Save ERROR:{0}, Stacktrace:{1}", e.Message, e.StackTrace); } }
internal void ForwardToWorld(int userSvrHandle, object msg) { try { if (null != msg) { byte[] data = m_UserChannel.Encode(msg); if (null != data) { Msg_LBL_Message builder = new Msg_LBL_Message(); builder.MsgType = Msg_LBL_Message.MsgTypeEnum.Room; builder.TargetName = "UserSvr"; builder.Data = data; m_UserChannel.Send(userSvrHandle, builder); } } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
internal void TransmitToWorld(int userSvrHandle, string nodeName, NodeMessage msg) { try { if (!string.IsNullOrEmpty(nodeName) && null != msg) { byte[] data = NodeMessageDispatcher.BuildNodeMessage(msg); if (null != data) { Msg_LBL_Message builder = new Msg_LBL_Message(); builder.MsgType = Msg_LBL_Message.MsgTypeEnum.Node; builder.TargetName = nodeName; builder.Data = data; m_UserChannel.Send(userSvrHandle, builder); } } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
internal static void Execute(object msg, User user) { Msg_CRC_Skill use_skill = msg as Msg_CRC_Skill; if (use_skill == null) { return; } CharacterInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.ERROR, "UseSkillHandler, charactor {0} not exist", user.RoleId); return; } charactor = charactor.GetRealControlledObject(); MovementStateInfo msi = charactor.GetMovementStateInfo(); if (!msi.IsSkillMoving) { float x = use_skill.stand_pos.x; float z = use_skill.stand_pos.z; float velocity = (float)user.Info.GetActualProperty().MoveSpeed; if (!user.VerifyPosition(x, z, velocity, use_skill.send_time, 4.0f)) { //todo:记录违规次数 } msi.SetPosition2D(x, z); user.SampleMoveData(use_skill.stand_pos.x, use_skill.stand_pos.z, velocity, msi.MoveDirCosAngle, msi.MoveDirSinAngle, use_skill.send_time); } msi.SetFaceDir(use_skill.face_direction); Scene scene = user.OwnRoom.GetActiveScene(); if (null != scene) { scene.SkillSystem.StartSkill(user.RoleId, use_skill.skill_id); } //LogSys.Log(LOG_TYPE.DEBUG, "UseSkillHandler User:{0} skill:{1} isskillmoving:{2} ismovemeetobstacle:{3} time:{4} client time:{5}", user.RoleId, use_skill.skill_id, msi.IsSkillMoving, msi.IsMoveMeetObstacle, TimeUtility.GetServerMilliseconds(), use_skill.send_time); }