gamerpc 6.0.6 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +53 -52
- package/src/authConn.js +25 -3
- package/src/gameConn.js +36 -3
- package/src/index.js +0 -38
- package/test/blockchain/test.js +5 -1
- package/test/game/auth.js +2 -2
- package/test/game/crm.js +1 -1
- package/test/game/mgr.js +80 -0
package/package.json
CHANGED
|
@@ -1,52 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "gamerpc",
|
|
3
|
-
"version": "
|
|
4
|
-
"author": "bookmansoft <ceo@920.cc>",
|
|
5
|
-
"contributors": [
|
|
6
|
-
"bookmansoft <ceo@920.cc>"
|
|
7
|
-
],
|
|
8
|
-
"license": "ISC",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"vallnet",
|
|
11
|
-
"bitcoin",
|
|
12
|
-
"gamegold",
|
|
13
|
-
"gamecloud",
|
|
14
|
-
"gameserver",
|
|
15
|
-
"gamelogic",
|
|
16
|
-
"cryptcurrency",
|
|
17
|
-
"rpc",
|
|
18
|
-
"cloud"
|
|
19
|
-
],
|
|
20
|
-
"description": "connector for gamecloud & gamegold",
|
|
21
|
-
"main": "index.js",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "mocha",
|
|
24
|
-
"build": "cross-env NODE_ENV=production webpack src/index.js --mode=production"
|
|
25
|
-
},
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/bookmansoft/gamegoldtoolkit.git"
|
|
29
|
-
},
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/bookmansoft/gamegoldtoolkit/issues"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/bookmansoft/gamegoldtoolkit#readme",
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"create-hmac": "1.1.7",
|
|
36
|
-
"elliptic": "^6.5.4",
|
|
37
|
-
"node-fetch": "^2.6.1",
|
|
38
|
-
"socket.io-client": "^2.
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"babel": "^6.
|
|
44
|
-
"babel-
|
|
45
|
-
"babel-
|
|
46
|
-
"babel-
|
|
47
|
-
"babel-preset-
|
|
48
|
-
"babel-preset-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "gamerpc",
|
|
3
|
+
"version": "7.1.0",
|
|
4
|
+
"author": "bookmansoft <ceo@920.cc>",
|
|
5
|
+
"contributors": [
|
|
6
|
+
"bookmansoft <ceo@920.cc>"
|
|
7
|
+
],
|
|
8
|
+
"license": "ISC",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"vallnet",
|
|
11
|
+
"bitcoin",
|
|
12
|
+
"gamegold",
|
|
13
|
+
"gamecloud",
|
|
14
|
+
"gameserver",
|
|
15
|
+
"gamelogic",
|
|
16
|
+
"cryptcurrency",
|
|
17
|
+
"rpc",
|
|
18
|
+
"cloud"
|
|
19
|
+
],
|
|
20
|
+
"description": "connector for gamecloud & gamegold",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "mocha",
|
|
24
|
+
"build": "set NODE_OPTIONS=--openssl-legacy-provider & cross-env NODE_ENV=production webpack ./src/index.js --mode=production"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/bookmansoft/gamegoldtoolkit.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/bookmansoft/gamegoldtoolkit/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/bookmansoft/gamegoldtoolkit#readme",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"create-hmac": "1.1.7",
|
|
36
|
+
"elliptic": "^6.5.4",
|
|
37
|
+
"node-fetch": "^2.6.1",
|
|
38
|
+
"socket.io-client": "^4.2.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"mocha": "^10.2.0",
|
|
42
|
+
"babel": "^6.23.0",
|
|
43
|
+
"babel-core": "^6.26.3",
|
|
44
|
+
"babel-loader": "^7.1.5",
|
|
45
|
+
"babel-plugin-transform-runtime": "^6.23.0",
|
|
46
|
+
"babel-preset-env": "^1.7.0",
|
|
47
|
+
"babel-preset-es2015": "^6.24.1",
|
|
48
|
+
"babel-preset-stage-2": "^6.24.1",
|
|
49
|
+
"cross-env": "^5.2.0",
|
|
50
|
+
"webpack": "^4.46.0",
|
|
51
|
+
"webpack-cli": "^3.3.2"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/authConn.js
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* 通过合适的打包程序,也可以用于浏览器环境
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const {
|
|
7
|
+
const assert = require('./utils/assert')
|
|
8
|
+
const {io, signHMAC, Base64, now, CommStatus, createHmac, ReturnCode, CommMode, NotifyType, encrypt, decrypt, stringify} = require('./utils/util');
|
|
9
|
+
let {sha1, hash160, hash256, verifyData, generateKey, signObj, verifyObj, verifyAddress} = require('./utils/verifyData');
|
|
10
|
+
const Secret = require('./utils/secret')
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* 终端配置管理
|
|
@@ -567,7 +569,27 @@ class AuthConn
|
|
|
567
569
|
}
|
|
568
570
|
}
|
|
569
571
|
|
|
572
|
+
AuthConn.prototype.CommMode = CommMode;
|
|
573
|
+
AuthConn.prototype.createHmac = createHmac;
|
|
574
|
+
AuthConn.prototype.assert = assert;
|
|
575
|
+
AuthConn.prototype.stringify = stringify;
|
|
576
|
+
AuthConn.prototype.encrypt = encrypt;
|
|
577
|
+
AuthConn.prototype.decrypt = decrypt;
|
|
578
|
+
AuthConn.prototype.verifyData = verifyData;
|
|
579
|
+
AuthConn.prototype.generateKey = generateKey;
|
|
580
|
+
AuthConn.prototype.signObj = signObj;
|
|
581
|
+
AuthConn.prototype.verifyObj = verifyObj;
|
|
582
|
+
AuthConn.prototype.verifyAddress = verifyAddress;
|
|
583
|
+
AuthConn.prototype.CommMode = CommMode;
|
|
584
|
+
AuthConn.prototype.CommStatus = CommStatus;
|
|
585
|
+
AuthConn.prototype.ReturnCode = ReturnCode;
|
|
586
|
+
AuthConn.prototype.NotifyType = NotifyType;
|
|
587
|
+
AuthConn.prototype.Secret = Secret;
|
|
588
|
+
AuthConn.prototype.hash256 = hash256;
|
|
589
|
+
AuthConn.prototype.hash160 = hash160;
|
|
590
|
+
AuthConn.prototype.sha1 = sha1;
|
|
591
|
+
|
|
570
592
|
/**
|
|
571
|
-
*
|
|
593
|
+
* 访问全节点的远程调用函数
|
|
572
594
|
*/
|
|
573
595
|
module.exports = AuthConn;
|
package/src/gameConn.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
const {extendObj, CommStatus, clone, ReturnCodeName, io, ReturnCode, CommMode,
|
|
1
|
+
const {stringify, NotifyType, encrypt, decrypt, extendObj, CommStatus, clone, ReturnCodeName, io, ReturnCode, CommMode, createHmac} = require('./utils/util');
|
|
2
2
|
const EventEmitter = require('events').EventEmitter;
|
|
3
3
|
const Indicator = require('./utils/Indicator');
|
|
4
|
+
const assert = require('./utils/assert')
|
|
5
|
+
let {sha1, hash160, hash256, verifyData, generateKey, signObj, verifyObj, verifyAddress} = require('./utils/verifyData');
|
|
6
|
+
const Secret = require('./utils/secret')
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* RPC控件
|
|
@@ -124,7 +127,7 @@ class Remote {
|
|
|
124
127
|
async getSign() {
|
|
125
128
|
console.log('gameconn: getSign');
|
|
126
129
|
//此处根据实际需要,发起了基于HTTP请求的认证访问,和本身创建时指定的通讯模式无关。
|
|
127
|
-
let router = this.userInfo.
|
|
130
|
+
let router = this.userInfo.openid.split('.')[0]; //openid一般由代表验证模式的前缀,加上代表节点类型的后缀组成, 获取签名接口的路由路径默认等于其前缀
|
|
128
131
|
let msg = await this.getRequest({}, router);
|
|
129
132
|
|
|
130
133
|
//客户端从模拟网关取得了签名集
|
|
@@ -249,8 +252,19 @@ class Remote {
|
|
|
249
252
|
}
|
|
250
253
|
|
|
251
254
|
if(options.domain) {
|
|
252
|
-
let authmode = options.
|
|
255
|
+
let authmode = options.openid.split('.')[0];
|
|
253
256
|
switch(authmode) {
|
|
257
|
+
case 'bxs': { //新增一种验证模式
|
|
258
|
+
this.setUserInfo({
|
|
259
|
+
domain: options.domain, //认证模式
|
|
260
|
+
openid: options.openid, //用户证书
|
|
261
|
+
openkey: options.openkey, //中间证书,经由Auth服务器转换成 openid 下发给客户端
|
|
262
|
+
auth: options.auth, //验证信息
|
|
263
|
+
}, CommStatus.reqLb);
|
|
264
|
+
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
|
|
254
268
|
case 'authwx': {
|
|
255
269
|
this.setUserInfo({
|
|
256
270
|
domain: options.domain, //认证模式
|
|
@@ -668,4 +682,23 @@ class Remote {
|
|
|
668
682
|
}
|
|
669
683
|
}
|
|
670
684
|
|
|
685
|
+
Remote.prototype.CommMode = CommMode;
|
|
686
|
+
Remote.prototype.createHmac = createHmac;
|
|
687
|
+
Remote.prototype.assert = assert;
|
|
688
|
+
Remote.prototype.stringify = stringify;
|
|
689
|
+
Remote.prototype.encrypt = encrypt;
|
|
690
|
+
Remote.prototype.decrypt = decrypt;
|
|
691
|
+
Remote.prototype.verifyData = verifyData;
|
|
692
|
+
Remote.prototype.generateKey = generateKey;
|
|
693
|
+
Remote.prototype.signObj = signObj;
|
|
694
|
+
Remote.prototype.verifyObj = verifyObj;
|
|
695
|
+
Remote.prototype.verifyAddress = verifyAddress;
|
|
696
|
+
Remote.prototype.CommStatus = CommStatus;
|
|
697
|
+
Remote.prototype.ReturnCode = ReturnCode;
|
|
698
|
+
Remote.prototype.NotifyType = NotifyType;
|
|
699
|
+
Remote.prototype.Secret = Secret;
|
|
700
|
+
Remote.prototype.hash256 = hash256;
|
|
701
|
+
Remote.prototype.hash160 = hash160;
|
|
702
|
+
Remote.prototype.sha1 = sha1;
|
|
703
|
+
|
|
671
704
|
module.exports = Remote;
|
package/src/index.js
CHANGED
|
@@ -46,42 +46,4 @@ toolkit.hash256 = hash256;
|
|
|
46
46
|
toolkit.hash160 = hash160;
|
|
47
47
|
toolkit.sha1 = sha1;
|
|
48
48
|
|
|
49
|
-
toolkit.conn.prototype.assert = assert;
|
|
50
|
-
toolkit.conn.prototype.stringify = stringify;
|
|
51
|
-
toolkit.conn.prototype.encrypt = encrypt;
|
|
52
|
-
toolkit.conn.prototype.decrypt = decrypt;
|
|
53
|
-
toolkit.conn.prototype.verifyData = verifyData;
|
|
54
|
-
toolkit.conn.prototype.generateKey = generateKey;
|
|
55
|
-
toolkit.conn.prototype.signObj = signObj;
|
|
56
|
-
toolkit.conn.prototype.verifyObj = verifyObj;
|
|
57
|
-
toolkit.conn.prototype.verifyAddress = verifyAddress;
|
|
58
|
-
toolkit.conn.prototype.CommMode = CommMode;
|
|
59
|
-
toolkit.conn.prototype.CommStatus = CommStatus;
|
|
60
|
-
toolkit.conn.prototype.ReturnCode = ReturnCode;
|
|
61
|
-
toolkit.conn.prototype.NotifyType = NotifyType;
|
|
62
|
-
toolkit.conn.prototype.createHmac = createHmac;
|
|
63
|
-
toolkit.conn.prototype.Secret = Secret;
|
|
64
|
-
toolkit.conn.prototype.hash256 = hash256;
|
|
65
|
-
toolkit.conn.prototype.hash160 = hash160;
|
|
66
|
-
toolkit.conn.prototype.sha1 = sha1;
|
|
67
|
-
|
|
68
|
-
toolkit.gameconn.prototype.assert = assert;
|
|
69
|
-
toolkit.gameconn.prototype.stringify = stringify;
|
|
70
|
-
toolkit.gameconn.prototype.encrypt = encrypt;
|
|
71
|
-
toolkit.gameconn.prototype.decrypt = decrypt;
|
|
72
|
-
toolkit.gameconn.prototype.verifyData = verifyData;
|
|
73
|
-
toolkit.gameconn.prototype.generateKey = generateKey;
|
|
74
|
-
toolkit.gameconn.prototype.signObj = signObj;
|
|
75
|
-
toolkit.gameconn.prototype.verifyObj = verifyObj;
|
|
76
|
-
toolkit.gameconn.prototype.verifyAddress = verifyAddress;
|
|
77
|
-
toolkit.gameconn.prototype.CommMode = CommMode;
|
|
78
|
-
toolkit.gameconn.prototype.CommStatus = CommStatus;
|
|
79
|
-
toolkit.gameconn.prototype.ReturnCode = ReturnCode;
|
|
80
|
-
toolkit.gameconn.prototype.NotifyType = NotifyType;
|
|
81
|
-
toolkit.gameconn.prototype.createHmac = createHmac;
|
|
82
|
-
toolkit.gameconn.prototype.Secret = Secret;
|
|
83
|
-
toolkit.gameconn.prototype.hash256 = hash256;
|
|
84
|
-
toolkit.gameconn.prototype.hash160 = hash160;
|
|
85
|
-
toolkit.gameconn.prototype.sha1 = sha1;
|
|
86
|
-
|
|
87
49
|
global.toolkit = toolkit;
|
package/test/blockchain/test.js
CHANGED
|
@@ -38,12 +38,16 @@ describe('模拟测试', () => {
|
|
|
38
38
|
console.log(ret);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
+
after(()=>{
|
|
42
|
+
remote.close();
|
|
43
|
+
});
|
|
44
|
+
|
|
41
45
|
it('WS模式监听消息', async () => {
|
|
42
46
|
await remote.setmode(remote.CommMode.ws);
|
|
43
47
|
|
|
44
48
|
//通过监听收到消息
|
|
45
49
|
remote.watch(msg => {
|
|
46
|
-
console.log(msg);
|
|
50
|
+
console.log('客户端收到订阅消息', msg);
|
|
47
51
|
}, 'tx.client');
|
|
48
52
|
|
|
49
53
|
//获得一个新的地址
|
package/test/game/auth.js
CHANGED
|
@@ -18,7 +18,7 @@ const remote = new gameconn({
|
|
|
18
18
|
//注意:如果需要负载均衡,这里一般指定负载均衡服务器地址,否则直接填写业务主机地址
|
|
19
19
|
"host": "127.0.0.1", //远程主机地址
|
|
20
20
|
"authPort": 9601, //签证主机端口
|
|
21
|
-
"port":
|
|
21
|
+
"port": 2102 //远程主机端口
|
|
22
22
|
},
|
|
23
23
|
}).setFetch(require('node-fetch')); //设置node环境下兼容的fetch函数
|
|
24
24
|
|
|
@@ -32,7 +32,7 @@ let phone_wx = ((Math.random() * 100000000) | 0).toString();
|
|
|
32
32
|
//用于验证后期绑定成功的用户证书缓存变量
|
|
33
33
|
let authUser = '';
|
|
34
34
|
|
|
35
|
-
describe
|
|
35
|
+
describe('钱包注册登录测试', () => {
|
|
36
36
|
it('用户注册并登录 - 使用两阶段认证模式', async () => {
|
|
37
37
|
//执行登录操作,通过配置对象传入用户信息,并指定签证方式为两阶段认证
|
|
38
38
|
let ret = await remote.init(/*初始化连接器,只保留原始配置信息*/).login({
|
package/test/game/crm.js
CHANGED
|
@@ -22,7 +22,7 @@ let username = `${(Math.random()*1000000)|0}@vallnet.cn`;
|
|
|
22
22
|
let password = crypto.createHash("sha1").update(((Math.random()*1000000)|0).toString() + salt).digest("hex");
|
|
23
23
|
let mobilephone = `139${((Math.random()*100000000)|0).toString()}`;
|
|
24
24
|
|
|
25
|
-
describe
|
|
25
|
+
describe('CRM注册登录', () => {
|
|
26
26
|
it('用户注册 - 通过两阶段认证模式实现', async () => {
|
|
27
27
|
//当用户点击'获取验证码'时执行如下流程:
|
|
28
28
|
let ret = await remote.init(/*初始化连接器,只保留原始配置信息*/).login({
|
package/test/game/mgr.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 联机单元测试:远程管理
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const assert = require('assert')
|
|
6
|
+
|
|
7
|
+
//引入游戏云连接器,创建连接器对象
|
|
8
|
+
const {gameconn} = require('../../src/')
|
|
9
|
+
const remote = new gameconn({
|
|
10
|
+
"UrlHead": "http", //协议选择: http/https
|
|
11
|
+
"webserver": {
|
|
12
|
+
//注意:如果需要负载均衡,这里一般指定负载均衡服务器地址,否则直接填写业务主机地址
|
|
13
|
+
"host": "127.0.0.1", //远程主机地址
|
|
14
|
+
"authPort": 9601, //签证主机端口
|
|
15
|
+
"port": 9901 //远程主机端口
|
|
16
|
+
},
|
|
17
|
+
}).setFetch(require('node-fetch')); //设置node环境下兼容的fetch函数
|
|
18
|
+
|
|
19
|
+
//切换为长连模式
|
|
20
|
+
//remote.setmode(remote.CommMode.ws);
|
|
21
|
+
|
|
22
|
+
//这里需要填充管理员登录信息
|
|
23
|
+
let admin = {
|
|
24
|
+
openid: '',
|
|
25
|
+
openkey: '',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('远程管理', () => {
|
|
29
|
+
it.skip('执行索引服远程指令 remote.printInfo', async () => {
|
|
30
|
+
await remote.init(/*初始化连接器,只保留原始配置信息*/).login({
|
|
31
|
+
domain: 'CoreOfIndex',
|
|
32
|
+
openid: admin.openid,
|
|
33
|
+
openkey: admin.openkey,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
let msg = await remote.fetching({func: "remote.printInfo"});
|
|
37
|
+
console.log(msg);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it.skip('透过索引服执行业务服远程指令 remote.command printInfo', async () => {
|
|
41
|
+
await remote.init(/*初始化连接器,只保留原始配置信息*/).login({
|
|
42
|
+
domain: 'CoreOfIndex',
|
|
43
|
+
openid: admin.openid,
|
|
44
|
+
openkey: admin.openkey,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
let msg = await remote.fetching({func: "remote.command", data: ['printInfo', 'CoreOfChickIOS', '1']});
|
|
48
|
+
console.log(msg);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('模拟用户注册并登录', async () => {
|
|
52
|
+
//执行登录操作,通过配置对象传入用户信息,并指定签证方式为两阶段认证
|
|
53
|
+
let auth = {
|
|
54
|
+
cpId: 'c376af60-cab5-11ed-90e8-25399b14218a',
|
|
55
|
+
addr: '10000000',
|
|
56
|
+
name: 'bookman',
|
|
57
|
+
bonus: '',
|
|
58
|
+
time: Date.now(),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//需要正确填充 auth.sign, 此处采用模拟命令填充, 注意命令 testSign 只在测试模式下开启
|
|
62
|
+
await remote.init().login({
|
|
63
|
+
domain: 'CoreOfIndex',
|
|
64
|
+
openid: admin.openid,
|
|
65
|
+
openkey: admin.openkey,
|
|
66
|
+
});
|
|
67
|
+
let msg = await remote.fetching({func: "remote.command", data: ['testSign', 'CoreOfChickIOS', '1', auth]});
|
|
68
|
+
auth.sign = msg['CoreOfChickIOS.1'].sign;
|
|
69
|
+
|
|
70
|
+
let ret = await remote.init().login({
|
|
71
|
+
domain: 'CoreOfChickIOS', //登录域
|
|
72
|
+
openid: `bxs.${auth.addr}`, //用户登录标识,含验证方式
|
|
73
|
+
auth,
|
|
74
|
+
});
|
|
75
|
+
if(!!ret) {
|
|
76
|
+
ret = await remote.fetching({func: "test.echo"});
|
|
77
|
+
assert(ret.code == 0);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|