private bool Reconnect(string handle, HoxisProtocolArgs args) { long uid = FF.StringToLong(args["uid"]); List <HoxisConnection> workers = HoxisServer.Ins.GetWorkingConnections(); foreach (HoxisConnection w in workers) { // If already signed in, response the state to let user choose if reconnecting if (w.user == this) { continue; } if (w.user.userID <= 0) { continue; } if (w.user.userID == uid) { userID = w.user.userID; realtimeData = w.user.realtimeData; Continue(); if (DebugRecorder.LogEnable(_logger)) { _logger.LogInfo("reconnect", ""); } HoxisServer.Ins.AffairEntry(C.AFFAIR_RELEASE_CONNECTION, w); return(ResponseSuccess(handle, "ReconnectCb")); } } return(Response(handle, "ReconnectCb", new KVString("code", C.RESP_NO_USER_INFO))); }
private bool SaveUserData(string handle, HoxisProtocolArgs args) { string json = args["data"]; //todo 写入数据库 return(ResponseSuccess(handle, "SaveUserDataCb")); }
/// <summary> /// Fill this HoxisUser with an connected user /// </summary> /// <param name="handle"></param> /// <param name="args"></param> /// <returns></returns> private bool SignIn(string handle, HoxisProtocolArgs args) { Ret ret; long uid = FF.StringToLong(args["uid"]); if (uid <= 0) { return(ResponseError(handle, C.RESP_ILLEGAL_ARGUMENT, FF.StringFormat("illegal argument: {0}", args["uid"]))); } userID = uid; connectionState = UserConnectionState.Default; if (DebugRecorder.LogEnable(_logger)) { _logger.LogInfo("sign in", ""); } else { _logger = new DebugRecorder(FF.StringAppend(HoxisServer.basicPath, @"logs\users\", NewUserLogName(uid)), out ret); if (ret.code != 0) { Console.WriteLine(ret.desc); } else { _logger.Begin(); _logger.LogInfo("sign in", ""); } } return(ResponseSuccess(handle, "SignInCb")); }
/// <summary> /// Reflect an action to method with protocol argument form /// </summary> /// <param name="method"></param> /// <param name="args"></param> public void Act(string method, HoxisProtocolArgs args) { if (!behavTable.ContainsKey(method)) { return; } behavTable[method](args); }
private bool LoadUserData(string handle, HoxisProtocolArgs args) { //todo 访问数据库,通过userID获取用户数据 //todo 转为json string json = ""; return(ResponseSuccess(handle, "LoadUserDataCb", new KVString("data", json))); }
private void QueryConnectionStateCb(HoxisProtocolArgs args) { string code = args["code"]; Debug.Log("QueryConnectionStateCb code: " + code); if (code == C.RESP_SUCCESS) { Debug.Log(args["state"]); } }
private bool SignOut(string handle, HoxisProtocolArgs args) { userID = 0; connectionState = UserConnectionState.None; if (DebugRecorder.LogEnable(_logger)) { _logger.LogInfo("sign out", ""); _logger.End(); } return(ResponseSuccess(handle, "SignOutCb")); }
private bool SetDefaultConnectionState(string handle, HoxisProtocolArgs args) { if (connectionState == UserConnectionState.Active) { connectionState = UserConnectionState.Default; return(ResponseSuccess(handle, "SetDefaultConnectionStateCb")); } else if (connectionState == UserConnectionState.Default) { return(Response(handle, "SetDefaultConnectionStateCb", new KVString("code", C.RESP_SET_DEFAULT_ALREADY))); } return(ResponseError(handle, C.RESP_SET_STATE_UNABLE, FF.StringFormat("current connection state is {0}", connectionState.ToString()))); }
/// <summary> /// Get the connection state if this user has already signed in /// </summary> /// <param name="handle"></param> /// <param name="args"></param> /// <returns></returns> private bool QueryConnectionState(string handle, HoxisProtocolArgs args) { long uid = FF.StringToLong(args["uid"]); if (uid <= 0) { return(ResponseError(handle, C.RESP_ILLEGAL_ARGUMENT, FF.StringFormat("illegal argument: {0}", args["uid"]))); } HoxisUser user = HoxisServer.Ins.GetUser(uid); if (user == null) { return(Response(handle, "QueryConnectionStateCb", new KVString("code", C.RESP_NO_USER_INFO))); } if (user == this) { return(Response(handle, "QueryConnectionStateCb", new KVString("code", C.RESP_NO_USER_INFO))); } return(ResponseSuccess(handle, "QueryConnectionStateCb", new KVString("state", user.connectionState.ToString()))); }
private void RefreshHeartbeatCb(HoxisProtocolArgs args) { string code = args["code"]; Debug.Log("RefreshHeartbeatCb code: " + code); }
private void ReconnectCb(HoxisProtocolArgs args) { string code = args["code"]; Debug.Log("ReconnectCb code: " + code); }
private void SignOutCb(HoxisProtocolArgs args) { string code = args["code"]; Debug.Log("SignOutCb code: " + code); }
private void SetDefaultConnectionStateCb(HoxisProtocolArgs args) { string code = args["code"]; Debug.Log("SetDefaultConnectionStateCb code: " + code); }
/// <summary> /// Make sure that the client is connected /// </summary> /// <param name="handle"></param> /// <param name="args"></param> /// <returns></returns> private bool RefreshHeartbeat(string handle, HoxisProtocolArgs args) { heartbeatTimer = 0; return(ResponseSuccess(handle, "RefreshHeartbeatCb")); }
void Shoot(HoxisProtocolArgs args) { Debug.Log("Hi, I'm attacked, args are " + args["val"] + ", " + args["src"]); this.name = "hahaha"; }