neo 1 рік тому
батько
коміт
85a2cf75f0
3 змінених файлів з 108 додано та 15 видалено
  1. 11 7
      dev/data/user.lua
  2. 3 2
      dev/modules/account.lua
  3. 94 6
      nodes/login/controllers/usr.lua

+ 11 - 7
dev/data/user.lua

@@ -29,15 +29,19 @@ function root:user_init_register_info(uid, info)
29 29
     moduleData:hset(uid, MODULE_NAME, "deviceId", info.deviceId or "")
30 30
     moduleData:hset(uid, MODULE_NAME, "channel", info.channel)
31 31
 
32
-    moduleData:hset(uid, MODULE_NAME, "nickname", string.format("玩家%06d", uid))
32
+    moduleData:hset(uid, MODULE_NAME, "nickname", info.nickname or string.format("玩家%06d", uid))
33 33
     -- 非测试环境随机密码
34
-    local password = "123456"
35
-    if not IS_TEST then
36
-        local r = {}
37
-        for i = 1, 8 do
38
-            table.insert(r, string.char(math.random(97, 122)))
34
+    local password = info.password
35
+    if is_nil(password) then
36
+        if not IS_TEST then
37
+            local r = {}
38
+            for i = 1, 8 do
39
+                table.insert(r, string.char(math.random(97, 122)))
40
+            end
41
+            password = table.concat(r)
42
+        else
43
+            password = "123456"
39 44
         end
40
-        password = table.concat(r)
41 45
     end
42 46
     moduleData:hset(uid, MODULE_NAME, "password", password)
43 47
     return true

+ 3 - 2
dev/modules/account.lua

@@ -1,8 +1,9 @@
1 1
 -- 账号
2 2
 local root = class("moduleAccount", require("base.baseModule"))
3 3
 
4
-function root:ctor()
5
-    root.super.ctor(self, nil, "account", "account")
4
+function root:ctor(account)
5
+    root.super.ctor(self, nil, "account", "account", true)
6
+    self.account = account
6 7
 end
7 8
 
8 9
 function root:mysql_get_init_columns()

+ 94 - 6
nodes/login/controllers/usr.lua

@@ -1,17 +1,14 @@
1 1
 local code = require "code"
2 2
 local tokenUtil = require "utils.tokenUtil"
3
-local nodeUtil = require("utils.nodeUtil")
4 3
 local serverLogUtil = require("utils.serverLogUtil")
4
+local util_user = require("utils.util_user")
5
+local accountModule = require("modules.accountModule")
5 6
 
6 7
 local lib_game_mysql = require("lib_game_mysql")
7 8
 local lib_game_redis = require("lib_game_redis")
8 9
 local moduleData = require("data.module")
9 10
 local userData = require("data.user")
10 11
 
11
-local lib_logger = require("log.lib_logger")
12
-local logRegister = lib_logger:new("register")
13
-local logLogin = lib_logger:new("login")
14
-
15 12
 local root = {}
16 13
 
17 14
 -- uuid注册
@@ -110,7 +107,7 @@ function root.login(msg)
110 107
         return code.USR.FORCE_OUT
111 108
     end
112 109
     -- 分配网关服务器
113
-    local nodeInfo = nodeUtil:user_dispatch_gate_node_and_agent(uid)
110
+    local nodeInfo = util_user:user_dispatch_gate_node(uid)
114 111
     if is_empty(nodeInfo) or is_empty(nodeInfo.ip) or is_empty(nodeInfo.wsPort) then
115 112
         return code.NOT_FOUND_SERVER
116 113
     end
@@ -150,4 +147,95 @@ function root.login(msg)
150 147
     return code.OK, ret
151 148
 end
152 149
 
150
+-- 注册 - 手机号
151
+function root.registerByPhone(msg)
152
+    local errCode, ret = l_uuid_register(msg)
153
+    if errCode then
154
+        return errCode, ret
155
+    end
156
+    local account = msg.phone
157
+    local password = msg.password
158
+    -- 账号信息
159
+    local accountObj = accountModule.new(account)
160
+    -- 已注册
161
+    if accountObj:get_data_from_db() then
162
+        -- return code.USR.ALREADY_REGISTER
163
+        return root.loginByPhone(msg)
164
+    end
165
+    local uid = l_get_register_uid()
166
+    -- 注册账号
167
+    moduleData:hset(account, "account", "account", account)
168
+    moduleData:hset(account, "account", "password", password)
169
+    moduleData:hset(account, "account", "uid", uid)
170
+    accountObj:backup_to_db()
171
+
172
+    -- 正常注册
173
+    userData:user_init_register_info(uid, msg)
174
+    -- 注册埋点
175
+    serverLogUtil.logRegister(uid, msg.channel, msg.version, msg.sysVer or "", msg.uuid, msg.udid, msg.ip)
176
+
177
+    return root.loginByPhone(msg)
178
+end
179
+-- 登录 - 手机号
180
+function root.loginByPhone(msg)
181
+    log.info("loginByPhone msg[%s]", tostring(msg))
182
+    local account, password = msg.account, msg.accountPassword
183
+    if not account or not password then
184
+        return code.PARAMTER_ERROR
185
+    end
186
+
187
+    local accountObj = accountModule.new(account)
188
+    if not accountObj:get_data_from_db() then
189
+        return code.USR.NOT_EXIST_USER
190
+    end
191
+
192
+    local psw = moduleData:hget(account, "account", "password")
193
+    if psw ~= password then
194
+        return code.USR.LOGIN_PASSWORD_ERROR
195
+    end
196
+
197
+    local uid = moduleData:hget(account, "account", "uid")
198
+    -- 状态
199
+    local status = moduleData:hget_int(uid, "user", "status")
200
+    if status > 0 then
201
+        return code.USR.FORCE_OUT
202
+    end
203
+    -- 分配网关服务器
204
+    local nodeInfo = util_user:user_dispatch_gate_node(uid)
205
+    if is_empty(nodeInfo) or is_empty(nodeInfo.ip) or is_empty(nodeInfo.wsPort) then
206
+        return code.NOT_FOUND_SERVER
207
+    end
208
+
209
+    -- 暂存登陆数据
210
+
211
+    -- 登陆埋点
212
+    serverLogUtil.logLogin(
213
+        uid,
214
+        msg.channel or "",
215
+        msg.version or "",
216
+        msg.sysVer or "",
217
+        msg.operator or "",
218
+        msg.network or "",
219
+        msg.uuid or "",
220
+        msg.udid or "",
221
+        msg.ip
222
+    )
223
+
224
+    local registerTime = moduleData:hget_int(uid, "user", "registerTime")
225
+    local password = moduleData:hget_int(uid, "user", "password")
226
+    local token = tokenUtil.create(uid, password)
227
+    local ret = {
228
+        sysTime = skynet_time(),
229
+        ip = nodeInfo.ip,
230
+        port = nodeInfo.port,
231
+        wsPort = nodeInfo.wsPort,
232
+        token = token,
233
+        uid = uid,
234
+        registerTime = registerTime
235
+    }
236
+
237
+    log.info("loginByPhone uid[%d] ret[%s]", tostring(uid), tostring(ret))
238
+    return code.OK, ret
239
+end
240
+
153 241
 return root