Login.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:6k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 游戏的登陆连接功能逻辑模块
  3. // Copyright : Kingsoft 2002-2003
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-8-13
  6. ------------------------------------------------------------------------------------------
  7. 状态机
  8.     参看KLoginDef.h文件获得相关一些登陆相关信息。
  9. *****************************************************************************************/
  10. #pragma once
  11. #include "LoginDef.h"
  12. #include "../NetConnect/NetMsgTargetObject.h"
  13. struct TProcessData;
  14. struct tagNewDelRoleResponse;
  15. struct tagNotifyPlayerLogin;
  16. enum LOGIN_LOGIC_STATUS
  17. {
  18. LL_S_IDLE = 0, //空闲
  19. LL_S_WAIT_INPUT_ACCOUNT, //等待传账号密码
  20. LL_S_ACCOUNT_CONFIRMING, //等待账号密码验证
  21. LL_S_WAIT_ROLE_LIST, //等待接收角色列表数据
  22. LL_S_ROLE_LIST_READY, //角色列表就绪
  23. LL_S_CREATING_ROLE, //正在新建角色
  24. LL_S_DELETING_ROLE, //正在删除角色
  25. LL_S_WAIT_TO_LOGIN_GAMESERVER, //等待登陆游戏服务器
  26. LL_S_ENTERING_GAME, //正在进入游戏
  27. LL_S_IN_GAME, //游戏运行时
  28. };
  29. enum LOGIN_LOGIC_RESULT_INFO
  30. {
  31. LL_R_NOTHING, //无结果信息
  32. LL_R_CONNECT_FAILED, //连接失败
  33. LL_R_CONNECT_SERV_BUSY, //服务器忙
  34. LL_R_CONNECT_TIMEOUT, //连接超时未获得响应
  35. LL_R_ACCOUNT_PWD_ERROR, //账号/密码错误
  36. LL_R_ACCOUNT_FREEZE, //账号冻结
  37. LL_R_ACCOUNT_LOCKED, //账号被锁定
  38. LL_R_INVALID_ROLENAME, //(新建)角色的名字不合法
  39. LL_R_SERVER_SHUTDOWN, //游戏服务器已满或正在维护中
  40. LL_R_INVALID_PROTOCOLVERSION, //版本号较旧,需要升级到新的客户端
  41. LL_R_INVALID_PASSWORD, //(删除角色时)提供的密码错误
  42. LL_R_ACCOUNT_CONFIRM_SUCCESS, //账号验证成功
  43. LL_R_CREATE_ROLE_SUCCESS, //创建角色成功
  44. LL_R_LOGIN_TO_GAMESERVER, //开始了与游戏世界服务器的连接
  45. LL_R_ACCOUNT_NOT_ENOUGH_POINT, //账号点数不足
  46. };
  47. #ifndef MAX_PLAYER_PER_ACCOUNT
  48. #define MAX_PLAYER_PER_ACCOUNT 3
  49. #endif
  50. //=====================================
  51. // 新建角色时需要的角色相关信息结构
  52. //=====================================
  53. struct KRoleChiefInfo
  54. {
  55. char Name[32]; //姓名
  56. unsigned char Gender; //性别 be one of the SSC_CHARACTER_GENDER value
  57. unsigned char Attribute; //五行属性
  58. union
  59. {
  60. unsigned short NativePlaceId; //出生地ID
  61. short nLevel; //等级
  62. };
  63. };
  64. struct KLoginServer
  65. {
  66. char Title[32]; //服务器文字说明
  67. unsigned char Address[4]; //服务器ip地址
  68. };
  69. class KLogin : public iKNetMsgTargetObject
  70. {
  71. public:
  72. KLogin(); //构造函数
  73. ~KLogin(); //析构函数
  74. //====iKNetMsgTargetObject接口函数====
  75. void AcceptNetMsg(void* pMsgData); //接受网络消息
  76. //====操作函数,它们一般引发状态跃迁====
  77. //与(账号)服务器建立连接
  78. int CreateConnection(const unsigned char* pAddress);
  79. //传入帐号密码,账号登陆
  80. int AccountLogin(const char* pAccount, const KSG_PASSWORD& crPassword, bool bOrignPassword = true);
  81. //选中游戏角色
  82. int SelectRole(int nIndex);
  83. //请求新建游戏角色
  84. int CreateRole(KRoleChiefInfo* pCreateInfo);
  85. //请求删除游戏角色
  86. int DeleteRole(int nIndex, const KSG_PASSWORD &crSupperPassword);
  87. //通知等待返回结果超时了
  88. void NotifyTimeout();
  89. //通知要开始游戏了
  90. void NotifyToStartGame();
  91. //通知网络连接(意外)断开了
  92. void NotifyDisconnect();
  93. //回到空闲状态
  94. void ReturnToIdle();
  95. //全程自动连接
  96. void AutoLogin();
  97. //判断是否可以执行全程自动连接
  98. int IsAutoLoginEnable();
  99. //设置纪录标记
  100. void SetRememberAccountFlag(bool bEnable);
  101. //设置纪录标记
  102. void SetRememberAllFlag(bool bEnable);
  103. //====数据获取函数====
  104. //获取登陆逻辑当前的状态
  105. LOGIN_LOGIC_STATUS GetStatus() { return m_Status; }
  106. //获取操作的结果信息
  107. LOGIN_LOGIC_RESULT_INFO GetResult();
  108. //获取角色的数目
  109. int GetRoleCount(int& nAdviceChoice);
  110. //获取某个角色的信息
  111. int GetRoleInfo(int nIndex, KRoleChiefInfo* pInfo);
  112. //保存登陆选择
  113. void SaveLoginChoice();
  114. //读取以前的的登陆选择
  115. void LoadLoginChoice();
  116. //获取服务器区域的列表
  117. KLoginServer* GetServerRegionList(int& nCount, int& nAdviceChoice);
  118. //登陆服务器列表获取
  119. KLoginServer* GetServerList(int nRegion, int& nCount, int& nAdviceChoice);
  120. //获取建议(旧的)登陆账号
  121. bool GetLoginAccount(char* pszAccount);
  122. //取得当前账号的剩余时间
  123. DWORD GetAccountLifeTime() { return m_LeftTime; }
  124. //判断当前角色是否为新建的角色
  125. int IsRoleNewCreated() { return m_Choices.bIsRoleNewCreated; }
  126.     //设置选中的服务器,用来存盘
  127.     int     SetAccountServer(const KLoginServer &rcSelectServer);
  128. private:
  129. //====各操作的网络响应的返回处理====
  130. void ProcessAccountLoginResponse(KLoginStructHead* pResponse); //处理账号登陆的响应
  131. void ProcessRoleListResponse(TProcessData* pResponse); //角色列表返回
  132. void ProcessDeleteRoleResponse(tagNewDelRoleResponse* pResponse); //删除角色列表的响应
  133. void ProcessCreateRoleResponse(tagNewDelRoleResponse* pResponse); //新建角色列表的响应
  134. void ProcessToLoginGameServResponse(tagNotifyPlayerLogin* pResponse);//准备登陆游戏服务器的响应
  135. //发送消息请求
  136. int Request(const char* pszAccount, const KSG_PASSWORD* pcPassword, int nAction);
  137. //连接账号服务器
  138. int ConnectAccountServer(const unsigned char* pIpAddress);
  139. void RegistNetAgent();
  140. void UnRegistNetAgent();
  141. void GetAccountPassword(char* pszAccount, KSG_PASSWORD* pPassword);
  142. void SetAccountPassword(const char* pszAccount, const KSG_PASSWORD* pcPassword);
  143. void ClearAccountPassword(bool bAccount, bool bPassword);
  144. private:
  145. LOGIN_LOGIC_STATUS m_Status;
  146. LOGIN_LOGIC_RESULT_INFO m_Result;
  147. bool m_bInAutoProgress; //是否正处于自动登陆过程中
  148. bool m_bReserved;
  149. short m_nNumRole; //角色的数目
  150. KRoleChiefInfo m_RoleList[MAX_PLAYER_PER_ACCOUNT];
  151. DWORD m_LeftTime;
  152. struct LOGIN_CHOICE
  153. {
  154. int nServerRegionIndex; //服务器区域索引
  155. KLoginServer AccountServer; //当前使用的服务器
  156. char Account[32]; //当前账号
  157. KSG_PASSWORD     Password; //当前账号的密码
  158. char szProcessingRoleName[32]; //当前处理的角色的名字
  159. bool bRememberAccount; //是否纪录登陆账号
  160. bool bRememberAll; //是否纪录全部的登陆选择
  161. bool bAutoLoginEnable; //是否允许自动登陆
  162. bool bIsRoleNewCreated; //当前角色是否为新建的角色
  163. bool bLoaded; //是否已加载选择纪录
  164. } m_Choices;
  165. };
  166. extern KLogin g_LoginLogic;