public override void ClientDisconnect(RPCUserInfo userInfo) { if (UserList.Contains(userInfo)) { UserList.Remove(userInfo); } }
public override void ClientDisconnect(RPCUserInfo userInfo) { if (UserList.Contains(userInfo)) { UserList.Remove(userInfo); Console.WriteLine((userInfo.UserToken as UserInfo).UserName + " 退出"); } }
/// <summary> /// 用户断开服务器触发 /// </summary> /// <param name="userInfo"></param> public override void ClientDisconnect(RPCUserInfo userInfo) { if (userInfo.UserToken != null) { UserInfo user = userInfo.UserToken as UserInfo; if (user != null) { string key = user.UserName; SpinWait.SpinUntil(() => UserList.TryRemove(key, out user)); //删除列表 } } UpdateUserList(this, UserList); SendUpdateUserlist(); }
private void DataOn(byte[] data, RPCUserInfo user) { ReadBytes read; int cmd; if (Service.CallModule(data, user, out read, out cmd)) { } else { if (BinaryInputOther != null) BinaryInputOther(read, cmd); } }
/// <summary> /// 创建注册 RPGUSERINFO /// </summary> /// <param name="socketAsync"></param> /// <returns></returns> private RPCUserInfo NewRPCUserInfo(SocketAsyncEventArgs socketAsync) { RPCUserInfo tmp = new RPCUserInfo(socketAsync); tmp.RPC_Call.ErrMsgOut += RPC_Call_ErrMsgOut; foreach (var item in RegModule) { tmp.RPC_Call.RegModule(item); } return tmp; }
public virtual void ClientDisconnect(RPCUserInfo userInfo) { return; }
/// <summary> /// 调用模块 /// </summary> /// <param name="data"></param> /// <returns>true 属于次模块,false 不属于此模块数据</returns> public bool CallModule(byte[] data, RPCUserInfo e,out ReadBytes read,out int cmd) { cmd = -1; read = new ReadBytes(data); int lengt; if (read.ReadInt32(out lengt) && read.Length == lengt && read.ReadInt32(out cmd)) { switch (cmd) { case 1001000: { RPCCallPack tmp; if (read.ReadObject<RPCCallPack>(out tmp)) { System.Threading.Tasks.Task.Factory.StartNew(() => { object returnValue; CallContext.SetData("Current", e); if (e.RPC_Call.RunModule(tmp, out returnValue)) { if (tmp.IsNeedReturn) { ZYClient_Result_Return var = new ZYClient_Result_Return() { Id = tmp.Id, CallTime = tmp.CallTime, Arguments = tmp.Arguments }; if (returnValue != null) { var.Return = Serialization.PackSingleObject(returnValue.GetType(), returnValue); var.ReturnType = returnValue.GetType(); } e.EnsureSend(BufferFormat.FormatFCA(var)); } } }, CancellationToken.None, TaskCreationOptions.None, e.QueueScheduler).ContinueWith(p => { try { p.Wait(); } catch (Exception er) { if (MsgOut != null) MsgOut(er.ToString()); } }); return true; } } break; case 1001001: { ZYClient_Result_Return val; if (read.ReadObject<ZYClient_Result_Return>(out val)) { e.RPC_Call.SetReturnValue(val); return true; } } break; } } return false; }
public void Disconnect(RPCUserInfo e) { foreach (var item in e.RPC_Call.ModuleDiy.Values) { Type type = item.GetType(); if (type.BaseType == typeof(RPCObject)) { type.GetMethod("ClientDisconnect").Invoke(item, new[] { e }); } } }