/// <summary> /// 客户端请求登录网关服务器 /// </summary> private ErrorCode OnMsgToGstoCsfromGcAskLogin(byte[] data, int offset, int size, int msgID) { if (!this._logicInited) { this.SetInited(true, true); } bool logMsgFlag = false; GCToCS.Login loginMsg = new GCToCS.Login(); GCToCS.Login login = new GCToCS.Login(); login.MergeFrom(data, offset, size); //验证token //正常登录流程是连接到登录服务器,再通过负载均衡服务器把消息转发给合适的网关服务器 //如果客户端绕过上述过程直接连接网关服务器并请求登录,则是非法操作 if (!GS.instance.gsStorage.IsUserCanLogin(login.Name, login.Passwd, this.id)) { Logger.Error($"user {login.Name} can't login with token {login.Passwd}"); GSToGC.NetClash msg = new GSToGC.NetClash(); //断开连接 GS.instance.PostToGameClient(this.id, msg, ( int )GSToGC.MsgID.EMsgToGcfromGsNotifyNetClash); GS.instance.PostGameClientDisconnect(this.id); return(ErrorCode.Success); } //获取IP INetSession pClient = GS.instance.GetSession(this.id); if (null != pClient) { EndPoint endPoint = pClient.connection.remoteEndPoint; if (endPoint == null) { Logger.Error($"user {login.Name} can't login with IP is null"); GS.instance.PostGameClientDisconnect(this.id); return(ErrorCode.Success); } logMsgFlag = true; loginMsg.Platform = login.Platform; loginMsg.Sdk = login.Sdk; loginMsg.Name = login.Name; loginMsg.Passwd = login.Passwd; loginMsg.Equimentid = login.Equimentid; loginMsg.Ipaddress = endPoint.ToString(); Logger.Log($"client({this.id}) ask login({loginMsg.Name})({loginMsg.Passwd})"); } //把登录信息转发到中心服务器 this.TransToCS(this.id, data, offset, size, msgID, logMsgFlag, loginMsg); return(ErrorCode.Success); }
/// <summary> /// 客户端请求重新登录 /// </summary> private ErrorCode OnMsgToGstoCsfromGcAskReconnectGame(byte[] data, int offset, int size, int msgID) { if (!this._logicInited) { this.SetInited(true, true); } GCToCS.ReconnectToGame reconnectToGame = new GCToCS.ReconnectToGame(); reconnectToGame.MergeFrom(data, offset, size); //验证token if (!GS.instance.gsStorage.IsUserCanLogin(reconnectToGame.Name, reconnectToGame.Passwd, this.id)) { Logger.Error($"user {reconnectToGame.Name} can't login with token {reconnectToGame.Passwd}"); GSToGC.NetClash msg = new GSToGC.NetClash(); GS.instance.PostToGameClient(this.id, msg, ( int )GSToGC.MsgID.EMsgToGcfromGsNotifyNetClash); GS.instance.PostGameClientDisconnect(this.id); } return(ErrorCode.Success); }
private void PostMsgToGC_NetClash() { GSToGC.NetClash sMsg = new GSToGC.NetClash(); this.PostMsgToGC(sMsg, ( int )GSToGC.MsgID.EMsgToGcfromGsNotifyNetClash); }