12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using Newtonsoft.Json.Linq;
- namespace ET.Server
- {
- /// <summary>
- /// 登入游戏服.获取角色列表
- /// </summary>
- [MessageHandler(SceneType.Game)]
- public class C2G_LoginGameHandler : AMRpcHandler<C2G_LoginGame, G2C_LoginGame>
- {
- protected override async ETTask Run(Session session, C2G_LoginGame request, G2C_LoginGame response, Action reply)
- {
- if (session.DomainScene().SceneType != SceneType.Game)
- {
- Log.Error($"Game 请求的Scene错误...SceneType={session.DomainScene().SceneType}");
- session.Dispose();
- return;
- }
- // 移除session自动超时组件
- session.RemoveComponent<SessionAcceptTimeoutComponent>();
- Scene scene = session.DomainScene();
- bool tokenIsNull = string.IsNullOrEmpty(request.Token.Trim());
- // 预先创建数据
- PlayerInfo playerInfo = new PlayerInfo();
- playerInfo.Id = IdGenerater.Instance.GenerateUnitId(scene.DomainZone());
- if (tokenIsNull)
- {
- // Token为空初始化信息
- playerInfo.RoomId = playerInfo.Id;
- playerInfo.AnchorOpenId = playerInfo.Id.ToString();
- playerInfo.AvatarUrl = "";
- playerInfo.Name = "主播-" + playerInfo.Id;
- playerInfo.TokenIsNull = true;
- }
- else
- {
- JObject roomInfo = scene.GetComponent<GameDouyinComponent>().GetRoomInfo(request.Token.Trim());
- if (roomInfo == null)
- {
- Log.Error($"获取抖音roomInfo失败...");
- response.Error = ErrorCode.ERR_RoomInfoError;
- reply();
- return;
- }
- JToken info = roomInfo.SelectToken("data").SelectToken("info");
- playerInfo.RoomId = Convert.ToInt64(info.SelectToken("room_id"));
- playerInfo.AnchorOpenId = Convert.ToString(info.SelectToken("anchor_open_id"));
- playerInfo.AvatarUrl = Convert.ToString(info.SelectToken("avatar_url"));
- playerInfo.Name = Convert.ToString(info.SelectToken("nick_name"));
- playerInfo.TokenIsNull = false;
- }
- playerInfo.Sex = 0;
- playerInfo.Pro = (int)PlayerProType.CANG_LANG;
- playerInfo.Level = 1;
- playerInfo.Exp = 0;
- // 添加session组件,用于绑定角色
- session.AddComponent<SessionPlayerComponent, PlayerInfo>(playerInfo);
- session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
- response.Player = PlayerHelper.PlayerInfoToPlayerBasicProto(playerInfo);
- reply();
- await ETTask.CompletedTask;
- }
- }
- }
|