-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientx.lua
More file actions
574 lines (465 loc) · 13.1 KB
/
clientx.lua
File metadata and controls
574 lines (465 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
--local dbg = require("emmy_core") --主动加载 emmy_core.dll
--dbg.tcpConnect('localhost', 9966)
--local base = _G
--local string = require("string")
--local math = require("math")
--local socket = require("socket.core")
--require "socket.core"
require "socket"
require "Debugger.LuaPanda".start("127.0.0.1", 8818)
--local class = require("clientcommon.class")
local CLIENT_ROOT = "./client/"
local LIB_ROOT = "./common/lib/"
local SERVER_ROOT = "./server/"
--package.cpath = "libs/?.dll"
--package.path = CLIENT_ROOT .. "?.lua;" .. SERVER_ROOT .. package.path
require "clientcommon.class"
local aaa = gCurPath
local NetSubSystem_Cls = require "NetSubSystem_C"
local tool = require "clientcommon.tool"
local ip = "192.168.2.19"
local port = 19001
local tempid = 10000
--加载Game的配置数据
local game_config = require("common.data.Config")
local tabdata = {}
game_config = game_config.init(tabdata)
local clientx = {}
local function log(...)
local str = table.concat(table.pack(...), " ")
print(string.format("\x1b[1;34m%d: %s\x1b[m", os.time(), str))
end
local function logf(...)
print(string.format("\x1b[1;34m%d: %s\x1b[m", os.time(), string.format(...)))
end
local function logerr(...)
print(string.format("\x1b[1;31m%d: %s\x1b[m", os.time(), string.format(...)))
end
local function logout(...)
infoLog(string.format("%d: %s", os.time(), string.format(...)))
end
local player = class("player")
local nMaxPlayer = 1
local runtimeObj
function gtick(t)
local success, res = xpcall(
function()
if runtimeObj then
runtimeObj.NetSubSystem:OnTick(0)
runtimeObj:randomOP()
end
end,
function(err)
return err .. ", " .. debug.traceback()
end
)
end
function gplayerjoin(uid)
local success, res = xpcall(
function()
if runtimeObj then
--runtimeObj.NetSubSystem:OnTick(0)
runtimeObj:DoEnterUser(tonumber(uid))
end
end,
function(err)
return err .. ", " .. debug.traceback()
end
)
end
--------------------------------------------------------------------------------
function player:Init(tid)
logerr("Init======================= ")
self.bLogin = false
self.tempid = tid
self.NetSubSystem = NetSubSystem_Cls.new()
self.NetSubSystem.player = self
self.NetSubSystem:Connect(ip, port)
end
--------------------------------------------------------------------------------
---登录
function player:DoLogin(Authtick)
local LoginCB = function(args)
args = args or {}
if args.timeout then
logerr("DoLogin Time out...")
return
end
self.bLogin = true
self.uid = args.uid
self.NetSubSystem.uid = args.uid
self.NetSubSystem:SetServerTime(args.timestamp)
self.canSend = true
logf("LoginCB %d", self.uid)
self:DoLoadPlayer(args.uid)
end
--登录游戏
self.NetSubSystem:RPC("Login", {
channel_type = 0,
account_type = 5,
lang = 1,
account_id = tostring(Authtick), --steam的票证
platform = 0,
channel_id = 0
}, LoginCB)
end
function player:DoNewRuntime(Authtick)
local NewRuntimeCB = function(args)
logout("NewRuntimeCB ...")
args = args or {}
if args.timeout then
logout("DoNewRuntime Time out...")
return
end
self.bLogin = true
self.uid = args.runid
self.NetSubSystem.uid = self.uid
self.NetSubSystem:SetServerTime(args.timestamp)
self.canSend = true
logout("NewRuntimeCB errorcode ... %d", tonumber(args.errcode))
logout("NewRuntimeCB %d", self.uid)
--self:DoLoadPlayer(args.uid)
--self:DoEnterUser(123)
end
--登录游戏
logout(" player:DoNewRuntime...")
logout(Authtick)
self.NetSubSystem:RPC("NewRuntime", {
runid = tostring(Authtick), --steam的票证
}, NewRuntimeCB)
end
function player:DoEnterUser(uid)
local EnterUserCB = function(args)
logout("EnterUserCB ...")
args = args or {}
if args.timeout then
logout("DoEnterUser Time out...")
return
end
local errcode = args.errcode
local timestamp = args.timestamp
logout("EnterUserCB errorcode ... %d", tonumber(args.errcode))
logout("EnterUserCB timestamp ... %d", tonumber(args.timestamp))
--self:DoLoadPlayer(args.uid)
end
--登录游戏
logout(" player:DoEnterUser...")
logout(uid)
self.NetSubSystem:RPC("EnterUser", {
runid = 987,
uid = uid,
}, EnterUserCB)
end
--加载玩家数据
function player:DoLoadPlayer(uid)
local LoadPlayerCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoLoadPlayer Time out...")
return
end
logerr("Activity======================= %s", tool.dump_table(args.player.personal.mission_groups[0]))
--clientx.UseBox(30000,2)
--clientx.UseBox(30001,2)
--clientx.UseBox(30002,1)
--clientx.UseBox(30005, 1)
--clientx.DoLoadMail()
--clientx.DoShopBuy()
--clientx.DoWearSkin()
--self:DoDisItems()
--self:GetRankInfo(0, 0)
self.NetSubSystem:RPC("LoadMail", {
uid = uid
}, nil)
end
self.canSend = false
--加载玩家数据
self.NetSubSystem:RPC("LoadPlayer", {
uid = uid
}, LoadPlayerCB)
end
function player:randomOP()
if self.NetSubSystem.bConnect and not self.bLogin then
infoLog("player:randomOP...")
--self:DoLogin(tostring(self.tempid))
self.bLogin = true
self:DoNewRuntime(tostring(self.tempid))
end
if self.NetSubSystem.bConnect and self.bLogin then
if not self.canSend then
return
end
if not self.bag then
--self:DoGetBagInfo()
--self:DoSaveRedpoint()
--self:DoReadRedpoint()
--self:DoJoinRoom()
return
end
--self:DoDisItems()
end
end
--使用宝匣
function player:UseBox(treasurebox_id, use_count)
local UseBoxCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("UseBoxCB Time out...")
return
end
local item_temp = game_config.ItemByid[treasurebox_id]
if item_temp.item_type == 4 then
--自选礼包
self:BoxSelect(treasurebox_id)
end
end
self.canSend = false
--加载玩家数据
self.NetSubSystem:RPC("UseTreasureBox", {
boxid = treasurebox_id,
count = use_count
}, UseBoxCB)
end
--自选宝匣
function player:BoxSelect(treasurebox_id)
local BoxSelectCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("BoxSelect Time out...")
return
end
end
self.canSend = false
--加载玩家数据
self.NetSubSystem:RPC("TreasuseBoxSelectItemBySelf", {
idindex = 1,
boxid = treasurebox_id
}, BoxSelectCB)
end
--获得排行榜数据
function player:GetRankInfo(rank_type, rank_index)
local GetRankInfoCB = function(args)
args = args or {}
if args.timeout then
logerr("GetRankInfo Time out...")
return
end
logerr("GetRankInfo errorcode %d", args.errorcode)
end
--加载玩家数据
self.NetSubSystem:RPC("GetRankInfo", {
ranktype = rank_type,
rankindex = rank_index
}, GetRankInfoCB)
end
--加载邮件
function player:DoLoadMail()
local LoadMailCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoLoadMail Time out...")
return
end
--自动领取有附件的邮件
args.mails = args.mails or {}
for k, v in pairs(args.mails) do
if v.attachment then
self:DoGetMail(k, 2)
end
end
end
self.canSend = false
--加载玩家数据
self.NetSubSystem:RPC("LoadMail", {
uid = self.uid
}, LoadMailCB)
end
--领取邮件
function player:DoGetMail(mail_id, op_type)
local GetMailCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoGetMail Time out...")
return
end
end
self.canSend = false
--加载玩家数据
self.NetSubSystem:RPC("MailReceive", {
mail_id = mail_id,
op_type = op_type,
}, GetMailCB)
end
--商店购买
function player:DoShopBuy()
local ShopBuyCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoShopBuy Time out...")
return
end
logerr("DoShopBuy errorcode %d", args.errorcode)
end
local product = {
productid = 10000,
productnum = 2
}
local products = {}
table.insert(products, product)
self.canSend = false
self.NetSubSystem:RPC("ShopBuy", {
uid = self.uid,
products = products
}, ShopBuyCB)
end
--穿戴
function player:DoWearSkin()
local WearSkinCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoWearSkin Time out...")
return
end
logerr("DoWearSkin errorcode %d", args.errorcode)
end
local block = {}
local idx = 3
block[idx] = {
idx = idx,
uniqid = "5f637b0c66e54c9b09466b8c7ff93fa7",
--uniqid = "",
itemid = 120001,
--itemid = 0,
}
self.canSend = false
self.NetSubSystem:RPC("WearSkin", {
uid = self.uid,
roleid = 10001,
block = block
}, WearSkinCB)
end
--分解道具
function player:DoDisItems()
local DisItemsCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoDisItems Time out...")
return
end
logerr("DoDisItems errorcode %d", args.errorcode)
end
local dislist = {}
for k, v in pairs(self.bag.uniqitems) do
if v.itemlist then
for uniqid, uniqitem in pairs(v.itemlist) do
if uniqitem and uniqitem.bindid == 0 then
table.insert(dislist, uniqitem)
break
end
end
break
end
end
self.canSend = false
self.NetSubSystem:RPC("DisItems", {
uid = self.uid,
items = {},
uniqitems = dislist,
}, DisItemsCB)
end
function player:DoGetBagInfo()
local GetBagInfoCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoGetBagInfo Time out...")
return
end
logerr("DoGetBagInfo errorcode %d", args.errorcode)
logerr("********run DoGetBagInfo", args.errorcode)
self.bag = args.baginfo
end
self.bag = {}
self.canSend = false
self.NetSubSystem:RPC("GetBagInfo", {
uid = self.uid,
}, GetBagInfoCB)
end
function player:DoSaveRedpoint()
local SaveRedpointCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoSaveRedpoint Time out...")
return
end
logerr("DoSaveRedpoint errorcode %d", args.errorcode)
end
self.NetSubSystem:RPC("SaveRedpoint", {
uid = self.uid,
redpoint_data = "123456",
}, SaveRedpointCB)
end
function player:DoReadRedpoint()
local ReadRedpointCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoReadRedpoint Time out...")
return
end
logerr("DoReadRedpoint errorcode %d", args.errorcode)
logerr("DoReadRedpoint redpoint_data %s", args.redpoint_data)
end
self.NetSubSystem:RPC("ReadRedpoint", {
uid = self.uid,
}, ReadRedpointCB)
end
--进入房间
function player:DoJoinRoom()
local JoinRoomCB = function(args)
self.canSend = true
args = args or {}
if args.timeout then
logerr("DoGetMail Time out...")
return
end
logerr("DoJoinRoom = %s ", tool.dump_table(args))
end
self.canSend = false
--加载玩家数据
self.NetSubSystem:RPC("JoinRoom", {
room_id = "",
uids = { self.uid },
party_id = "",
room_type = 1,
}, JoinRoomCB)
end
function main()
local success, res = xpcall(
function()
runtimeObj = player.new()
runtimeObj:Init(tempid)
infoLog("runtimeObj.new...")
infoLog(tempid)
tempid = tempid + 1
end,
function(err)
return err .. ", " .. debug.traceback()
end
)
if not success then
logerr(res)
end
--while true do
--end
end
main()