forked from sin365/AxibugEmuOnline
用户通知 | 改名| 用户管理 | 以及前后端逻辑
This commit is contained in:
parent
1ffe9e79c0
commit
029044cc0e
@ -5,6 +5,15 @@
|
||||
// 添加你自己需要的事件类型
|
||||
OnChatMsg,
|
||||
|
||||
//自己的信息更新(比如改名更新)
|
||||
OnSelfInfoUpdate,
|
||||
//更新其他用户信息
|
||||
OnOtherUserInfoUpdate,
|
||||
|
||||
//用户列表,登录和离开
|
||||
OnUserListAllUpdate,
|
||||
OnUserLogin,
|
||||
OnUserLoginOut,
|
||||
|
||||
OnRoomListAllUpdate,//房间列表全量刷新
|
||||
OnRoomListSingleAdd,//房间列表中新增房间
|
||||
|
@ -9,10 +9,12 @@ namespace AxibugEmuOnline.Client
|
||||
public PostProcessVolume m_filterVolume;
|
||||
public CanvasGroup m_filterPreview;
|
||||
public CanvasGroup m_xmbBg;
|
||||
public static string dev_UUID;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
App.Init(this);
|
||||
dev_UUID = SystemInfo.deviceUniqueIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using AxibugEmuOnline.Client.Common;
|
||||
using AxibugEmuOnline.Client.Network;
|
||||
using AxibugProtobuf;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AxibugEmuOnline.Client.Manager
|
||||
{
|
||||
@ -22,11 +23,23 @@ namespace AxibugEmuOnline.Client.Manager
|
||||
LastLoginGuid = Guid.NewGuid().ToString();
|
||||
|
||||
App.user.userdata.Account = LastLoginGuid;
|
||||
AxibugProtobuf.DeviceType devType;
|
||||
if (Application.platform == RuntimePlatform.PSP2)
|
||||
devType = AxibugProtobuf.DeviceType.Psv;
|
||||
else if (Application.platform == RuntimePlatform.Android)
|
||||
devType = AxibugProtobuf.DeviceType.Android;
|
||||
else if (Application.platform == RuntimePlatform.IPhonePlayer)
|
||||
devType = AxibugProtobuf.DeviceType.Ios;
|
||||
else
|
||||
devType = AxibugProtobuf.DeviceType.Pc;
|
||||
|
||||
Protobuf_Login msg = new Protobuf_Login()
|
||||
{
|
||||
LoginType = 0,
|
||||
Account = App.user.userdata.Account,
|
||||
LoginType = LoginType.UseDevice,
|
||||
DeviceStr = Initer.dev_UUID,
|
||||
DeviceType = devType,
|
||||
};
|
||||
|
||||
App.network.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg));
|
||||
}
|
||||
|
||||
@ -40,6 +53,8 @@ namespace AxibugEmuOnline.Client.Manager
|
||||
|
||||
App.log.Info("获取Room列表");
|
||||
App.roomMgr.SendGetRoomList();
|
||||
App.log.Info("获取在线玩家列表");
|
||||
App.user.Send_GetUserList();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,4 +1,12 @@
|
||||
using AxibugEmuOnline.Client.ClientCore;
|
||||
using AxibugEmuOnline.Client.Common;
|
||||
using AxibugEmuOnline.Client.Event;
|
||||
using AxibugEmuOnline.Client.Network;
|
||||
using AxibugProtobuf;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine.EventSystems;
|
||||
using static AxibugEmuOnline.Client.ClientCore.RomDB;
|
||||
|
||||
namespace AxibugEmuOnline.Client.Manager
|
||||
{
|
||||
@ -6,6 +14,7 @@ namespace AxibugEmuOnline.Client.Manager
|
||||
{
|
||||
public long UID { get; set; }
|
||||
public string Account { get; set; }
|
||||
public string NickName { get; set; }
|
||||
}
|
||||
|
||||
public class MainUserDataBase : UserDataBase
|
||||
@ -19,19 +28,29 @@ namespace AxibugEmuOnline.Client.Manager
|
||||
{
|
||||
//注册重连成功事件,以便后续自动登录
|
||||
App.network.OnReConnected += OnReConnected;
|
||||
|
||||
//网络事件注册
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserOnlinelist, RecvUserOnlinelist);
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserJoin, RecvCmdUserJoin);
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserLeave, RecvGetUserLeave);
|
||||
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdModifyNickName, RecvModifyNickName);
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUpdateSelfUserInfo, RecvUpdateSelfUserInfo);
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUpdateOtherUserInfo, RecvUpdateOtherUserInfo);
|
||||
}
|
||||
|
||||
public MainUserDataBase userdata { get; private set; } = new MainUserDataBase();
|
||||
public bool IsLoggedIn => userdata.IsLoggedIn;
|
||||
|
||||
Dictionary<long, UserDataBase> DictUID2User = new Dictionary<long, UserDataBase>();
|
||||
public int OnlinePlayerCount => DictUID2User.Count;
|
||||
public void InitMainUserData(string UName, long UID)
|
||||
{
|
||||
userdata.Account = UName;
|
||||
userdata.NickName = UName;
|
||||
userdata.IsLoggedIn = true;
|
||||
userdata.UID = UID;
|
||||
//以及其他数据初始化
|
||||
//...
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登出
|
||||
/// </summary>
|
||||
@ -41,7 +60,6 @@ namespace AxibugEmuOnline.Client.Manager
|
||||
//以及其他数据清理
|
||||
//...
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当重连成功
|
||||
/// </summary>
|
||||
@ -53,5 +71,143 @@ namespace AxibugEmuOnline.Client.Manager
|
||||
App.login.Login();
|
||||
}
|
||||
}
|
||||
|
||||
#region 角色管理
|
||||
public void UpdateOrAddUser(UserMiniInfo minfo, out bool isNewUser)
|
||||
{
|
||||
lock (DictUID2User)
|
||||
{
|
||||
if (!DictUID2User.ContainsKey(minfo.UID))
|
||||
{
|
||||
DictUID2User[minfo.UID] = new UserDataBase()
|
||||
{
|
||||
UID = minfo.UID,
|
||||
NickName = minfo.NickName,
|
||||
Account = "",
|
||||
};
|
||||
isNewUser = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isNewUser = false;
|
||||
DictUID2User[minfo.UID].NickName = minfo.NickName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveUser(long UID)
|
||||
{
|
||||
bool bflag = false;
|
||||
string UName = "";
|
||||
lock (DictUID2User)
|
||||
{
|
||||
if (DictUID2User.ContainsKey(UID))
|
||||
{
|
||||
UName = DictUID2User[UID].NickName;
|
||||
DictUID2User.Remove(UID);
|
||||
bflag = true;
|
||||
}
|
||||
}
|
||||
if (bflag)
|
||||
{
|
||||
//抛出用户离开事件
|
||||
Eventer.Instance.PostEvent(EEvent.OnUserLoginOut, UID, UName);
|
||||
}
|
||||
}
|
||||
public UserDataBase GetUserByUid(long UID)
|
||||
{
|
||||
lock (DictUID2User)
|
||||
{
|
||||
if (DictUID2User.ContainsKey(UID))
|
||||
{
|
||||
return DictUID2User[UID];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public UserDataBase[] GetUserList()
|
||||
{
|
||||
UserDataBase[] ulist = new UserDataBase[DictUID2User.Count];
|
||||
long[] UIDs = DictUID2User.Keys.ToArray();
|
||||
for (int i = 0; i < UIDs.Length; i++)
|
||||
{
|
||||
ulist[i] = DictUID2User[UIDs[i]];
|
||||
}
|
||||
return ulist;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 请求拉取房间列表
|
||||
/// </summary>
|
||||
public void Send_GetUserList()
|
||||
{
|
||||
Protobuf_UserList msg = new Protobuf_UserList()
|
||||
{
|
||||
};
|
||||
App.network.SendToServer((int)CommandID.CmdUserOnlinelist, ProtoBufHelper.Serizlize(msg));
|
||||
}
|
||||
|
||||
public void RecvUserOnlinelist(byte[] reqData)
|
||||
{
|
||||
Protobuf_UserList_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_UserList_RESP>(reqData);
|
||||
for (int i = 0; i < msg.UserList.Count; i++)
|
||||
{
|
||||
UserMiniInfo mi = msg.UserList[i];
|
||||
UpdateOrAddUser(mi, out bool isNewUser);
|
||||
}
|
||||
Eventer.Instance.PostEvent(EEvent.OnUserListAllUpdate);
|
||||
}
|
||||
public void RecvCmdUserJoin(byte[] reqData)
|
||||
{
|
||||
Protobuf_UserJoin_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_UserJoin_RESP>(reqData);
|
||||
UpdateOrAddUser(msg.UserInfo, out bool isNewUser);
|
||||
if (isNewUser)
|
||||
Eventer.Instance.PostEvent(EEvent.OnUserLogin, msg.UserInfo.UID, msg.UserInfo.NickName);
|
||||
}
|
||||
|
||||
public void RecvGetUserLeave(byte[] reqData)
|
||||
{
|
||||
Protobuf_UserLeave_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_UserLeave_RESP>(reqData);
|
||||
RemoveUser(msg.UID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送修改昵称请求
|
||||
/// </summary>
|
||||
/// <param name="NickName"></param>
|
||||
public void Send_ModifyNickName(string NickName)
|
||||
{
|
||||
Protobuf_Modify_NickName msg = new Protobuf_Modify_NickName()
|
||||
{
|
||||
NickName = NickName
|
||||
};
|
||||
App.network.SendToServer((int)CommandID.CmdModifyNickName, ProtoBufHelper.Serizlize(msg));
|
||||
}
|
||||
|
||||
void RecvModifyNickName(byte[] reqData)
|
||||
{
|
||||
Protobuf_Modify_NickName_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_Modify_NickName_RESP>(reqData);
|
||||
}
|
||||
|
||||
private void RecvUpdateSelfUserInfo(byte[] reqData)
|
||||
{
|
||||
Protobuf_Update_UserInfo_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_Update_UserInfo_RESP>(reqData);
|
||||
userdata.NickName = msg.UserInfo.NickName;
|
||||
Eventer.Instance.PostEvent(EEvent.OnSelfInfoUpdate);
|
||||
}
|
||||
|
||||
private void RecvUpdateOtherUserInfo(byte[] reqData)
|
||||
{
|
||||
Protobuf_Update_OtherUserInfo_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_Update_OtherUserInfo_RESP>(reqData);
|
||||
UserDataBase userdata = GetUserByUid(msg.UID);
|
||||
if (userdata == null)
|
||||
return;
|
||||
userdata.NickName = msg.UserInfo.NickName;
|
||||
//TODO其他
|
||||
Eventer.Instance.PostEvent(EEvent.OnOtherUserInfoUpdate, msg.UID);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
||||
public enum EEvent
|
||||
{
|
||||
// 添加你自己需要的事件类型
|
||||
OnUserJoin,
|
||||
OnUserLeave
|
||||
OnUserOnline,
|
||||
OnUserOffline
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace AxibugEmuOnline.Server
|
||||
public static LogManager g_Log;
|
||||
public static LoginManager g_Login;
|
||||
public static ChatManager g_Chat;
|
||||
public static UserManager g_UserMgr;
|
||||
public static IOCPNetWork g_SocketMgr;
|
||||
public static RoomManager g_Room;
|
||||
|
||||
@ -26,6 +27,7 @@ namespace AxibugEmuOnline.Server
|
||||
g_Log = new LogManager();
|
||||
g_Login = new LoginManager();
|
||||
g_Chat = new ChatManager();
|
||||
g_UserMgr = new UserManager();
|
||||
g_SocketMgr = new IOCPNetWork(1024, 4096*2);
|
||||
g_Room = new RoomManager();
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
using AxibugEmuOnline.Server.Common;
|
||||
using AxibugEmuOnline.Server.Event;
|
||||
using AxibugEmuOnline.Server.NetWork;
|
||||
using AxibugProtobuf;
|
||||
using MySql.Data.MySqlClient;
|
||||
using MySqlX.XDevAPI;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using System.Timers;
|
||||
|
||||
@ -9,12 +13,14 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
public class ClientInfo
|
||||
{
|
||||
public long UID { get; set; }
|
||||
public string NickName { get; set; }
|
||||
public string Account { get; set; }
|
||||
public string NickName { get; set; } = string.Empty;
|
||||
public string Account { get; set; } = string.Empty;
|
||||
public Socket _socket { get; set; }
|
||||
public bool IsOffline { get; set; } = false;
|
||||
public DateTime RegisterDT { get; set; }
|
||||
public DateTime LogOutDT { get; set; }
|
||||
public DateTime LogInDT { get; set; }
|
||||
public DateTime LastLogInDT { get; set; }
|
||||
public UserRoomState RoomState { get; set; } = new UserRoomState();
|
||||
public TimeSpan LastStartPingTime { get; set; }
|
||||
public int LastPingSeed { get; set; }
|
||||
@ -81,6 +87,7 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
threadPingTick.Start();
|
||||
}
|
||||
|
||||
|
||||
public long GetNextUID()
|
||||
{
|
||||
return ++TestUIDSeed;
|
||||
@ -104,7 +111,7 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
//通用处理
|
||||
#region clientlist 处理
|
||||
|
||||
public ClientInfo JoinNewClient(Protobuf_Login data, Socket _socket)
|
||||
public ClientInfo JoinNewClient(long _uid, Socket _socket)
|
||||
{
|
||||
//也许这个函数需加lock
|
||||
ClientInfo cinfo = GetClientForSocket(_socket);
|
||||
@ -117,10 +124,8 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
{
|
||||
cinfo = new ClientInfo()
|
||||
{
|
||||
UID = GetNextUID(),
|
||||
UID = _uid,
|
||||
_socket = _socket,
|
||||
Account = data.Account,
|
||||
NickName = data.Account,
|
||||
IsOffline = false,
|
||||
};
|
||||
AddClient(cinfo);
|
||||
@ -192,6 +197,10 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
}
|
||||
}
|
||||
|
||||
public ClientInfo GetClientForUID(long UID)
|
||||
{
|
||||
return _DictUIDClient.ContainsKey(UID) ? _DictUIDClient[UID] : null;
|
||||
}
|
||||
|
||||
public ClientInfo GetClientForSocket(Socket sk)
|
||||
{
|
||||
@ -221,8 +230,8 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
Console.WriteLine("标记玩家UID" + cinfo.UID + "为离线");
|
||||
cinfo.IsOffline = true;
|
||||
cinfo.LogOutDT = DateTime.Now;
|
||||
|
||||
AppSrv.g_Room.LeaveRoom(cinfo, cinfo.RoomState.RoomID);
|
||||
EventSystem.Instance.PostEvent(EEvent.OnUserOffline, cinfo.UID);
|
||||
}
|
||||
|
||||
public void RemoveClientForSocket(Socket sk)
|
||||
@ -264,7 +273,6 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
public void OnCmdPing(Socket sk, byte[] reqData)
|
||||
{
|
||||
//AppSrv.g_Log.Debug($"OnCmdPing");
|
||||
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(sk);
|
||||
Protobuf_Ping msg = ProtoBufHelper.DeSerizlize<Protobuf_Ping>(reqData);
|
||||
|
||||
//创建成功下行
|
||||
@ -272,7 +280,7 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
{
|
||||
Seed = msg.Seed,
|
||||
};
|
||||
AppSrv.g_ClientMgr.ClientSend(_c._socket, (int)CommandID.CmdPong, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
|
||||
AppSrv.g_ClientMgr.ClientSend(sk, (int)CommandID.CmdPong, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
|
||||
}
|
||||
public void OnCmdPong(Socket sk, byte[] reqData)
|
||||
{
|
||||
@ -303,6 +311,7 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public void ClientSendALL(int CMDID, int ERRCODE, byte[] data, long SkipUID = -1)
|
||||
{
|
||||
ClientSend(ClientList, CMDID, ERRCODE, data, SkipUID);
|
||||
|
@ -1,6 +1,9 @@
|
||||
using AxibugEmuOnline.Server.Common;
|
||||
using AxibugEmuOnline.Server.Event;
|
||||
using AxibugEmuOnline.Server.NetWork;
|
||||
using AxibugProtobuf;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Org.BouncyCastle.Ocsp;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace AxibugEmuOnline.Server.Manager
|
||||
@ -10,24 +13,214 @@ namespace AxibugEmuOnline.Server.Manager
|
||||
public LoginManager()
|
||||
{
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdLogin, UserLogin);
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdModifyNickName, OnCmdModifyNickName);
|
||||
}
|
||||
|
||||
public void UserLogin(Socket _socket, byte[] reqData)
|
||||
void UserLogin(Socket _socket, byte[] reqData)
|
||||
{
|
||||
AppSrv.g_Log.Debug("收到新的登录请求");
|
||||
AppSrv.g_Log.DebugCmd("UserLogin");
|
||||
Protobuf_Login msg = ProtoBufHelper.DeSerizlize<Protobuf_Login>(reqData);
|
||||
ClientInfo _c = AppSrv.g_ClientMgr.JoinNewClient(msg, _socket);
|
||||
long _uid = 0;
|
||||
|
||||
AppSrv.g_Log.Info($"LoginType -> {msg.LoginType.ToString()}");
|
||||
if (msg.LoginType == LoginType.UseDevice)
|
||||
{
|
||||
if (!GetUidByDevice(msg.DeviceStr, msg.DeviceType, out _uid))
|
||||
{
|
||||
byte[] ErrRespData = ProtoBufHelper.Serizlize(new Protobuf_Login_RESP()
|
||||
{
|
||||
Status = LoginResultStatus.AccountErr,
|
||||
});
|
||||
AppSrv.g_ClientMgr.ClientSend(_socket, (int)CommandID.CmdLogin, (int)ErrorCode.ErrorOk, ErrRespData);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] ErrRespData = ProtoBufHelper.Serizlize(new Protobuf_Login_RESP()
|
||||
{
|
||||
Status = LoginResultStatus.AccountErr,
|
||||
});
|
||||
AppSrv.g_ClientMgr.ClientSend(_socket, (int)CommandID.CmdLogin, (int)ErrorCode.ErrorOk, ErrRespData);
|
||||
return;
|
||||
}
|
||||
|
||||
ClientInfo _c = AppSrv.g_ClientMgr.JoinNewClient(_uid, _socket);
|
||||
|
||||
UpdateUserData(_uid, _c);
|
||||
|
||||
EventSystem.Instance.PostEvent(EEvent.OnUserOnline, _c.UID);
|
||||
|
||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Login_RESP()
|
||||
{
|
||||
Status = LoginResultStatus.Ok,
|
||||
RegDate = "",
|
||||
LastLoginDate = "",
|
||||
RegDate = _c.RegisterDT.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
LastLoginDate = _c.LastLogInDT.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
Token = "",
|
||||
NickName = _c.NickName,
|
||||
UID = _c.UID
|
||||
});
|
||||
|
||||
AppSrv.g_Log.Info($"玩家登录成功 UID->{_c.UID} NikeName->{_c.NickName}");
|
||||
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdLogin, (int)ErrorCode.ErrorOk, respData);
|
||||
}
|
||||
|
||||
void OnCmdModifyNickName(Socket socket, byte[] reqData)
|
||||
{
|
||||
AppSrv.g_Log.DebugCmd("OnCmdModifyNikeName");
|
||||
bool bDone = false;
|
||||
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(socket);
|
||||
Protobuf_Modify_NickName msg = ProtoBufHelper.DeSerizlize<Protobuf_Modify_NickName>(reqData);
|
||||
MySqlConnection conn = Haoyue_SQLPoolManager.DequeueSQLConn("ModifyNikeName");
|
||||
try
|
||||
{
|
||||
string query = "update users set nikename = ?nikename where uid = ?uid ";
|
||||
using (var command = new MySqlCommand(query, conn))
|
||||
{
|
||||
// 设置参数值
|
||||
command.Parameters.AddWithValue("?uid", _c.UID);
|
||||
command.Parameters.AddWithValue("?uid", msg.NickName);
|
||||
|
||||
if (command.ExecuteNonQuery() > 0)
|
||||
{
|
||||
bDone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
Haoyue_SQLPoolManager.EnqueueSQLConn(conn);
|
||||
|
||||
if (bDone)
|
||||
{
|
||||
_c.NickName = msg.NickName;
|
||||
|
||||
UserMiniInfo miniinfo = new UserMiniInfo()
|
||||
{
|
||||
NickName = _c.NickName,
|
||||
};
|
||||
|
||||
Protobuf_Update_UserInfo_RESP infodata = new Protobuf_Update_UserInfo_RESP()
|
||||
{
|
||||
UserInfo = miniinfo,
|
||||
};
|
||||
//回执给自己
|
||||
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdUpdateSelfUserInfo, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(infodata));
|
||||
|
||||
Protobuf_Update_OtherUserInfo_RESP otherinfo = new Protobuf_Update_OtherUserInfo_RESP()
|
||||
{
|
||||
UID = _c.UID,
|
||||
UserInfo = miniinfo
|
||||
};
|
||||
//广播给他人
|
||||
AppSrv.g_ClientMgr.ClientSendALL((int)CommandID.CmdUpdateOtherUserInfo, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(otherinfo), SkipUID: _c.UID);
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetUidByDevice(string deviceStr, DeviceType DeviceType, out long uid)
|
||||
{
|
||||
uid = 0;
|
||||
bool bDone = true;
|
||||
MySqlConnection conn = Haoyue_SQLPoolManager.DequeueSQLConn("GetUidByDevice");
|
||||
try
|
||||
{
|
||||
string query = "SELECT uid from user_devices where device = ?deviceStr ";
|
||||
using (var command = new MySqlCommand(query, conn))
|
||||
{
|
||||
// 设置参数值
|
||||
command.Parameters.AddWithValue("?deviceStr", deviceStr);
|
||||
// 执行查询并处理结果
|
||||
using (var reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
uid = reader.GetInt64(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (uid > 0)
|
||||
{
|
||||
AppSrv.g_Log.Info($"设备串:{deviceStr} 对应 UID:{uid}");
|
||||
}
|
||||
else
|
||||
{
|
||||
query = "INSERT INTO `haoyue_emu`.`users` (`nikename`, `regdate`, `lastlogindate`) VALUES (NULL,now(),now());SELECT LAST_INSERT_ID(); ";
|
||||
using (var command = new MySqlCommand(query, conn))
|
||||
{
|
||||
// 设置参数值
|
||||
// 执行查询并处理结果
|
||||
using (var reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
uid = reader.GetInt64(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query = "INSERT INTO `haoyue_emu`.`user_devices` (`device`, `devicetype`, `uid`) VALUES (?deviceStr, ?DeviceType, ?uid);";
|
||||
using (var command = new MySqlCommand(query, conn))
|
||||
{
|
||||
command.Parameters.AddWithValue("?deviceStr", deviceStr);
|
||||
command.Parameters.AddWithValue("?DeviceType", (int)DeviceType);
|
||||
command.Parameters.AddWithValue("?uid", uid);
|
||||
if (command.ExecuteNonQuery() < 1)
|
||||
bDone = false;
|
||||
}
|
||||
|
||||
AppSrv.g_Log.Info($"创建新账户,设备:{deviceStr},设备类型:{DeviceType.ToString()},是否成功:{bDone}");
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
bDone = false;
|
||||
}
|
||||
Haoyue_SQLPoolManager.EnqueueSQLConn(conn);
|
||||
|
||||
if (uid <= 0)
|
||||
bDone = false;
|
||||
return bDone;
|
||||
}
|
||||
|
||||
public void UpdateUserData(long uid, ClientInfo _c)
|
||||
{
|
||||
MySqlConnection conn = Haoyue_SQLPoolManager.DequeueSQLConn("UpdateUserData");
|
||||
try
|
||||
{
|
||||
string query = "SELECT account,nikename,regdate,lastlogindate from users where uid = ?uid ";
|
||||
using (var command = new MySqlCommand(query, conn))
|
||||
{
|
||||
// 设置参数值
|
||||
command.Parameters.AddWithValue("?uid", uid);
|
||||
// 执行查询并处理结果
|
||||
using (var reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
|
||||
_c.Account = reader.IsDBNull(0) ? string.Empty : reader.GetString(0);
|
||||
_c.NickName = reader.IsDBNull(1) ? string.Empty:reader.GetString(1);
|
||||
_c.LogInDT = DateTime.Now;
|
||||
_c.RegisterDT = reader.IsDBNull(2) ? DateTime.Now : reader.GetDateTime(2);
|
||||
_c.LastLogInDT = reader.IsDBNull(3) ? DateTime.Now : reader.GetDateTime(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
query = "update users set lastlogindate = now() where uid = ?uid ";
|
||||
using (var command = new MySqlCommand(query, conn))
|
||||
{
|
||||
command.Parameters.AddWithValue("?uid", uid);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
Haoyue_SQLPoolManager.EnqueueSQLConn(conn);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ using AxibugEmuOnline.Server.NetWork;
|
||||
using AxibugProtobuf;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using static System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
|
||||
namespace AxibugEmuOnline.Server
|
||||
{
|
||||
|
81
AxibugEmuOnline.Server/Manager/UserManager.cs
Normal file
81
AxibugEmuOnline.Server/Manager/UserManager.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using AxibugEmuOnline.Server.Common;
|
||||
using AxibugEmuOnline.Server.Event;
|
||||
using AxibugEmuOnline.Server.NetWork;
|
||||
using AxibugProtobuf;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace AxibugEmuOnline.Server.Manager
|
||||
{
|
||||
public class UserManager
|
||||
{
|
||||
public UserManager()
|
||||
{
|
||||
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserOnlinelist, RecvGetUserList);
|
||||
|
||||
//事件
|
||||
EventSystem.Instance.RegisterEvent<long>(EEvent.OnUserOnline, OnUserJoin);
|
||||
EventSystem.Instance.RegisterEvent<long>(EEvent.OnUserOffline, OnUserLeave);
|
||||
}
|
||||
|
||||
#region 事件
|
||||
void OnUserJoin(long UID)
|
||||
{
|
||||
AppSrv.g_Log.Debug($"P2PUserManager->OnUserJoin UID->{UID}");
|
||||
SendUserJoin(UID);
|
||||
}
|
||||
void OnUserLeave(long UID)
|
||||
{
|
||||
AppSrv.g_Log.Debug($"P2PUserManager->OnUserLeave UID->{UID}");
|
||||
SendUserLeave(UID);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void RecvGetUserList(Socket _socket, byte[] reqData)
|
||||
{
|
||||
Protobuf_UserList msg = ProtoBufHelper.DeSerizlize<Protobuf_UserList>(reqData);
|
||||
|
||||
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForSocket(_socket);
|
||||
Protobuf_UserList_RESP respData = new Protobuf_UserList_RESP();
|
||||
|
||||
ClientInfo[] cArr = AppSrv.g_ClientMgr.GetOnlineClientList().ToArray();
|
||||
respData.UserCount = cArr.Length;
|
||||
for (int i = 0; i < cArr.Length; i++)
|
||||
{
|
||||
ClientInfo client = cArr[i];
|
||||
respData.UserList.Add(new UserMiniInfo()
|
||||
{
|
||||
NickName = client.NickName,
|
||||
UID = client.UID,
|
||||
});
|
||||
}
|
||||
AppSrv.g_Log.Debug($"拉取用户列表->{respData.UserCount}个用户");
|
||||
AppSrv.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdUserOnlinelist, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respData));
|
||||
}
|
||||
|
||||
|
||||
public void SendUserJoin(long UID)
|
||||
{
|
||||
ClientInfo _c = AppSrv.g_ClientMgr.GetClientForUID(UID);
|
||||
if (_c == null)
|
||||
return;
|
||||
UserMiniInfo miniInfo = new UserMiniInfo();
|
||||
|
||||
miniInfo.NickName = _c.NickName;
|
||||
UID = _c.UID;
|
||||
Protobuf_UserJoin_RESP resp = new Protobuf_UserJoin_RESP()
|
||||
{
|
||||
UserInfo = miniInfo
|
||||
};
|
||||
AppSrv.g_ClientMgr.ClientSendALL((int)CommandID.CmdUserJoin, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
|
||||
}
|
||||
|
||||
public void SendUserLeave(long UID)
|
||||
{
|
||||
Protobuf_UserLeave_RESP resp = new Protobuf_UserLeave_RESP()
|
||||
{
|
||||
UID = UID,
|
||||
};
|
||||
AppSrv.g_ClientMgr.ClientSendALL((int)CommandID.CmdUserLeave, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ namespace AxibugEmuOnline.Server.NetWork
|
||||
|
||||
private void ClientNumberChange(int num, AsyncUserToken token)
|
||||
{
|
||||
Console.WriteLine("Client数发生变化");
|
||||
Console.WriteLine($"Client数发生变化 num->{num}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -12,6 +12,15 @@ enum CommandID
|
||||
|
||||
CMD_LOGIN = 2001; //自动登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP
|
||||
|
||||
CMD_USER_ONLINELIST = 3000; //获取在线用户列表 上行 | 下行 对应 Protobuf_UserList | Protobuf_UserList_RESP
|
||||
CMD_USER_JOIN = 3031; //用户上线 下行 对应 Protobuf_UserOnline_RESP
|
||||
CMD_USER_LEAVE = 3032; //用户下线 下行 对应 Protobuf_UserOffline_RESP
|
||||
CMD_USER_STATE_UPDATE = 3033; //更新在线用户状态 下行 对应 Protobuf_UserState_RESP
|
||||
|
||||
CMD_Modify_NickName = 3101; //修改名称上行 | 下行 对应 Protobuf_Modify_NickName | Protobuf_Modify_NickName_RESP
|
||||
CMD_Update_SelfUserInfo = 3110; //更新用户信息 下行 Protobuf_Update_UserInfo_RESP
|
||||
CMD_Update_OtherUserInfo = 3112; //更新其他用户信息 下行 Protobuf_Update_OtherUserInfo_RESP
|
||||
|
||||
CMD_CHATMSG = 4001; //广播聊天信息上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
|
||||
|
||||
//房间列表相关(仅用于列表显示)
|
||||
@ -70,7 +79,9 @@ enum ErrorCode
|
||||
|
||||
enum LoginType
|
||||
{
|
||||
BaseDefault = 0;//缺省不使用
|
||||
UseDevice = 0;//使用设备登录
|
||||
UseAccount = 1;//使用账户
|
||||
UseHaoYueAccount = 2;//使用皓月通行证
|
||||
}
|
||||
|
||||
enum DeviceType
|
||||
@ -135,16 +146,17 @@ message Protobuf_Pong
|
||||
//登录数据上行
|
||||
message Protobuf_Login
|
||||
{
|
||||
LoginType loginType = 1;//登录操作类型 [0]皓月通行证 [3] 皓月BF3 [4] 皓月BF4
|
||||
LoginType loginType = 1;//登录操作类型
|
||||
DeviceType deviceType = 2;//设备类型 [0] PC [1] AndroidPad预留 [3] IPad预留
|
||||
string Account = 3;//用户名
|
||||
string Password = 4;//密码
|
||||
string deviceStr = 3;//设备串
|
||||
string Account = 4;//用户名
|
||||
string Password = 5;//密码
|
||||
}
|
||||
|
||||
//登录数据下行
|
||||
message Protobuf_Login_RESP
|
||||
{
|
||||
string DeviceUUID = 1;//设备唯一串
|
||||
string NickName = 1;//昵称(第一次是自动生成)
|
||||
string Token = 2;//登录凭据 (本次登录之后,所有业务请求凭据,需要存储在内存中)
|
||||
string LastLoginDate = 3;//上次登录时间(只用于呈现的字符串,若界面需求需要)
|
||||
string RegDate = 4;//注册时间(只用于呈现的字符串,若界面需求需要)
|
||||
@ -152,6 +164,70 @@ message Protobuf_Login_RESP
|
||||
int64 UID = 6;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//获取在线用户列表 上行
|
||||
message Protobuf_UserList
|
||||
{
|
||||
}
|
||||
|
||||
//获取在线用户列表 下行
|
||||
message Protobuf_UserList_RESP
|
||||
{
|
||||
int32 UserCount = 1;//玩家数量
|
||||
repeated UserMiniInfo UserList = 2;//用户列表
|
||||
}
|
||||
|
||||
//用户上线 下行
|
||||
message Protobuf_UserJoin_RESP
|
||||
{
|
||||
UserMiniInfo UserInfo = 1;//用户
|
||||
}
|
||||
|
||||
//用户下线 下行
|
||||
message Protobuf_UserLeave_RESP
|
||||
{
|
||||
int64 UID = 1;//用户ID
|
||||
}
|
||||
|
||||
//更新在线用户状态 下行
|
||||
message Protobuf_UserState_RESP
|
||||
{
|
||||
int64 UID = 1;//用户ID
|
||||
int32 State = 2;//状态
|
||||
}
|
||||
|
||||
message UserMiniInfo
|
||||
{
|
||||
int64 UID = 1;//用户ID
|
||||
string NickName = 2;//昵称
|
||||
}
|
||||
|
||||
//修改昵称上行
|
||||
message Protobuf_Modify_NickName
|
||||
{
|
||||
string NickName = 1;//昵称
|
||||
}
|
||||
|
||||
//修改昵称下行
|
||||
message Protobuf_Modify_NickName_RESP
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//用户信息更新
|
||||
message Protobuf_Update_UserInfo_RESP
|
||||
{
|
||||
UserMiniInfo UserInfo = 1;//用户
|
||||
}
|
||||
|
||||
//其他用户信息更新
|
||||
message Protobuf_Update_OtherUserInfo_RESP
|
||||
{
|
||||
int64 UID = 1;//用户ID
|
||||
UserMiniInfo UserInfo = 2;//用户
|
||||
}
|
||||
|
||||
message Protobuf_Room_List
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user