fofstudio-aimcpztdata 1.0.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.
@@ -0,0 +1,6 @@
1
+ exports.BufferClassToArrar = function (Data) {
2
+ return Array.from(new Uint8Array(Data))
3
+ }
4
+ exports.ArrarToBufferClass = function (Data) {
5
+ return Buffer.from(Data)
6
+ }
@@ -0,0 +1,57 @@
1
+ let Data = {};
2
+ exports.NewID = function (ID, dataHead, dataEnd) {
3
+ try {
4
+ if (Data.length >= 500) {
5
+ for (let key in Data) {
6
+ delete Data[key];
7
+ break;
8
+ }
9
+ }
10
+ Data[ID] = {
11
+ "data1": [],
12
+ "dataHead": dataHead,
13
+ "dataEnd": dataEnd
14
+ };
15
+ } catch (error) {
16
+
17
+ }
18
+ }
19
+ exports.InsertData = function (ID, Data_) {
20
+ try {
21
+ if (Data[ID] != undefined) {
22
+ Data[ID].data1.splice(Data[ID].data1.length, 0, ...Array.from(new Uint8Array(Data_)));
23
+ }
24
+ } catch (error) {
25
+
26
+ }
27
+ }
28
+ exports.SelectData = function (ID) {
29
+ try {
30
+ Data[ID].data1.splice(0, Data[ID].dataHead.length)
31
+ Data[ID].data1.splice(Data[ID].data1.length - Data[ID].dataEnd.length, Data[ID].dataEnd.length)
32
+ return Buffer.from(Data[ID].data1)
33
+ } catch (error) {
34
+ return Buffer.from([])
35
+ }
36
+ }
37
+ exports.IFDataLength = function (ID) {
38
+ try {
39
+ let IfDataLength = true;
40
+ for (let index = 0; index < Data[ID].dataEnd.length; index++) {
41
+ if (Data[ID].data1[Data[ID].data1.length - index - 1] != Data[ID].dataEnd[Data[ID].dataEnd.length - index - 1]) {
42
+ IfDataLength = false;
43
+ }
44
+ }
45
+ return IfDataLength;
46
+ } catch (error) {
47
+
48
+ }
49
+ return false;
50
+ }
51
+ exports.DeleteData = function (ID) {
52
+ try {
53
+ delete Data[ID];
54
+ } catch (error) {
55
+
56
+ }
57
+ }
@@ -0,0 +1,30 @@
1
+ exports.TextDecoder = (Decoder, Code, hexTrue = false, hexCode = "hex") => {
2
+ if (hexTrue == true) {
3
+ return Buffer.from(Code, hexCode).toString(Decoder)
4
+ }
5
+ const decoder = new TextDecoder(Decoder);
6
+ return decoder.decode(Code);
7
+ }
8
+ exports.TextDecoderBase64 = (Decoder, Code) => {
9
+ var b = new Buffer.from(Code, 'base64')
10
+ const decoder = new TextDecoder(Decoder);
11
+ let deCode = decoder.decode(b);
12
+ b = Buffer.from(deCode).toString('base64')
13
+ return b;
14
+ }
15
+ exports.TextToBase64 = (Code) => {
16
+ var b = Buffer.from(Code).toString('base64')
17
+ return b;
18
+ }
19
+ exports.Base64ToText = (Code) => {
20
+ var b = new Buffer.from(Code, 'base64')
21
+ return b.toString();
22
+ }
23
+ exports.TextTo16 = (Code) => {
24
+ var b = Buffer.from(Code).toString('hex')
25
+ return b;
26
+ }
27
+ exports.HexToText = (Code) => {
28
+ var b = new Buffer.from(Code, 'hex')
29
+ return b.toString();
30
+ }
@@ -0,0 +1,48 @@
1
+ const { dialog } = require('electron');
2
+ exports.showOpenDialogSync = (data) => {
3
+ try {
4
+ let PathRet = dialog.showOpenDialogSync({
5
+ properties: ["openDirectory"],
6
+ title: data["名称"],
7
+ defaultPath: data["路径"],
8
+ buttonLabel: '确认选择'
9
+ });
10
+ return PathRet;
11
+ } catch (err) {
12
+ return "";
13
+ }
14
+ }
15
+ exports.showOpenDialogSyncFile = (data) => {
16
+ try {
17
+ let type = data["类型"];
18
+ if(type==2){
19
+ let PathRet = dialog.showOpenDialogSync({
20
+ properties: ["openDirectory"],
21
+ title: data["标题"],
22
+ defaultPath: data["路径"],
23
+ buttonLabel: data["按钮标题"]
24
+ });
25
+ return PathRet;
26
+ }else{
27
+ let filters = [];
28
+ for (let index = 0; index < data["过滤器"].length; index++) {
29
+ filters[filters.length] = { name: data["过滤器"][index]["名称"], extensions: data["过滤器"][index]["类型"] }
30
+ }
31
+ if (filters.length >= 1) {
32
+ type = ["openFile"]
33
+ let PathRet = dialog.showOpenDialogSync({
34
+ properties: type,
35
+ defaultPath: data["路径"],
36
+ title: data["标题"],
37
+ buttonLabel: data["按钮标题"],
38
+ filters: filters
39
+ })
40
+ return PathRet;
41
+ } else {
42
+ return [];
43
+ }
44
+ }
45
+ } catch (err) {
46
+ return [];
47
+ }
48
+ }
@@ -0,0 +1,64 @@
1
+ const { spawn } = require('child_process');
2
+ let iconv = null;
3
+ try {
4
+ iconv = require('iconv-lite');
5
+ } catch (error) {
6
+
7
+ }
8
+ var spawnArr = [];//记录打开其他程序的对象
9
+ exports.OpenEXE = (path) => {
10
+ try {
11
+ if (process.platform == 'darwin') {
12
+ var childSpawn = spawn(path + "/Contents/MacOS/Electron", [path], {
13
+ stdio: 'ignore',
14
+ });
15
+ spawnArr[spawnArr.length] = { "id": childSpawn, "type": 0 };
16
+ return path + "/Contents/MacOS/Electron";
17
+ } else {
18
+ var childSpawn = spawn(path);
19
+ spawnArr[spawnArr.length] = { "id": childSpawn, "type": 0 };
20
+ return spawnArr.length - 1;
21
+ }
22
+ } catch (error) {
23
+ return -1;
24
+ }
25
+ }
26
+ exports.KillEXE = (kill) => {
27
+ try {
28
+ if (spawnArr[kill]["type"] == 0) {
29
+ spawnArr[kill]["id"].kill();
30
+ spawnArr[kill]["type"] = -1;
31
+ }
32
+ } catch (error) {
33
+
34
+ }
35
+ }
36
+ exports.DoesTheProcessExist = (query, cb, encoding = "GBK") => {
37
+ const execs = require('child_process').exec;
38
+ let platform = process.platform;
39
+ let cmd = '';
40
+ switch (platform) {
41
+ case 'win32': cmd = `tasklist`; break;
42
+ case 'darwin': cmd = `ps -ax | grep ${query}`; break;
43
+ case 'linux': cmd = `ps -A`; break;
44
+ default: break;
45
+ }
46
+ let cwd = {
47
+ cwd: "",
48
+ encoding: "GBK",
49
+ }
50
+ execs(cmd, cwd, (err, stdout, stderr) => {
51
+ try {
52
+ const utf8Stdout = iconv.decode(Buffer.from(stdout, 'binary'), encoding);
53
+ if (cmd.indexOf("ps -ax |") != -1) {
54
+ cb(utf8Stdout.toLowerCase().indexOf(query.toLowerCase()) > -1 && utf8Stdout.toLowerCase().indexOf("applications") > -1);
55
+ } else {
56
+ cb(utf8Stdout.toLowerCase().indexOf(query.toLowerCase()) > -1);
57
+ }
58
+ } catch (error) {
59
+ cb(false)
60
+ }
61
+
62
+ });
63
+ }
64
+
@@ -0,0 +1,309 @@
1
+ const net = require('net')
2
+ let ServerArr = [];
3
+ let IPBlacklist = [];
4
+ var player = [];
5
+ var idObj = {};
6
+ exports.InsertIPBlacklist = function (ip) {
7
+ IPBlacklist[IPBlacklist.length] = ip;
8
+ }
9
+ exports.NewServer = function (ServerData, MsgFun = undefined) {
10
+ ServerArr[ServerArr.length] = null;
11
+ let IntServer = ServerArr.length - 1;
12
+ idObj[IntServer] = {};
13
+ ServerArr[IntServer] = net.createServer((socket) => {
14
+ socket.on('data', (dt) => {
15
+ for (let index = 0; index < IPBlacklist.length; index++) {
16
+ let IPStr = IPBlacklist[index];
17
+ if (IPStr == undefined) {
18
+ continue;
19
+ }
20
+ if (socket.remoteFamily != undefined) {
21
+ if (socket.remoteFamily == IPStr) {
22
+ socket.destroy()
23
+ }
24
+ }
25
+ if (socket.remoteAddress != undefined) {
26
+ if (socket.remoteAddress == IPStr) {
27
+ socket.destroy()
28
+ }
29
+ }
30
+ }
31
+ if (MsgFun != undefined) {
32
+ let RetData = MsgFun({
33
+ "状态": "收到数据",
34
+ "本地端口地址": socket.localPort,
35
+ "本地IP地址": socket.localAddress,
36
+ "进程端口地址": socket.remotePort,
37
+ "进程IP协议": socket.remoteFamily,
38
+ "进程IP地址": socket.remoteAddress,
39
+ "数据内容": dt,
40
+ "id": socket.socketIdxos,
41
+ "接收长度": socket.bytesRead
42
+ })
43
+ if (RetData == undefined) {
44
+ RetData = {}
45
+ }
46
+ try {
47
+ if (RetData["是否反馈"] != undefined) {
48
+ if (RetData["是否反馈"] == true) {
49
+ if (RetData["反馈数据"] != "") {
50
+ socket.write(RetData["反馈数据"]);
51
+ }
52
+ }
53
+ }
54
+ if (RetData["是否断开"] != undefined) {
55
+ if (RetData["是否断开"] == true) {
56
+ socket.destroy()
57
+ }
58
+ }
59
+ } catch (err) {
60
+
61
+ }
62
+ }
63
+ })
64
+ socket.on('close', (dt) => {
65
+ ServerArr[IntServer].getConnections(function (err, count) {
66
+ try {
67
+ delete idObj[IntServer][socket.socketIdxos]
68
+ } catch (error) {
69
+
70
+ }
71
+ if (MsgFun != undefined) {
72
+ MsgFun({
73
+ "状态": "客户下线",
74
+ "连接总量": count,
75
+ "本地端口地址": socket.localPort,
76
+ "本地IP地址": socket.localAddress,
77
+ "进程端口地址": socket.remotePort,
78
+ "进程IP协议": socket.remoteFamily,
79
+ "id": socket.socketIdxos,
80
+ "进程IP地址": socket.remoteAddress
81
+ })
82
+ }
83
+ });
84
+ })
85
+ socket.on('end', (dt) => {
86
+ let RetData = MsgFun({
87
+ "状态": "任务完毕",
88
+ "本地端口地址": socket.localPort,
89
+ "本地IP地址": socket.localAddress,
90
+ "进程端口地址": socket.remotePort,
91
+ "进程IP协议": socket.remoteFamily,
92
+ "id": socket.socketIdxos,
93
+ "进程IP地址": socket.remoteAddress
94
+ })
95
+ if (RetData == undefined) {
96
+ RetData = {}
97
+ }
98
+ try {
99
+ if (RetData["是否反馈"] != undefined) {
100
+ if (RetData["是否反馈"] == true) {
101
+ if (RetData["反馈数据"] != "") {
102
+ socket.write(RetData["反馈数据"]);
103
+ }
104
+ }
105
+ }
106
+ if (RetData["是否断开"] != undefined) {
107
+ if (RetData["是否断开"] == true) {
108
+ socket.destroy()
109
+ }
110
+ }
111
+ } catch (err) {
112
+
113
+ }
114
+ })
115
+
116
+ })
117
+ if (ServerData["端口"] == undefined) {
118
+ ServerData["端口"] = 3000
119
+ }
120
+ if (ServerData["地址"] == undefined) {
121
+ ServerData["地址"] = "0.0.0.0"
122
+ }
123
+ if (ServerData["最大连接数"] == undefined) {
124
+ ServerData["最大连接数"] = 1000;
125
+ }
126
+ ServerArr[IntServer].listen(ServerData["端口"], ServerData["地址"], () => {
127
+ ServerArr[IntServer].maxConnections = ServerData["最大连接数"];
128
+ if (MsgFun != undefined) {
129
+ MsgFun({ "状态": "启动服务成功" })
130
+ }
131
+ })
132
+ ServerArr[IntServer].on('connection', socket => {
133
+ //7.获取客户度接入的数量:
134
+ ServerArr[IntServer].getConnections(function (err, count) {
135
+ let socketIdxos = player.length + 1;
136
+ player[player.length] = socketIdxos
137
+ socket.socketIdxos = socketIdxos
138
+ idObj[IntServer][socketIdxos] = socket;
139
+ if (MsgFun != undefined) {
140
+ let RetData = MsgFun({
141
+ "状态": "新的接入",
142
+ "连接总量": count,
143
+ "本地端口地址": socket.localPort,
144
+ "本地IP地址": socket.localAddress,
145
+ "进程端口地址": socket.remotePort,
146
+ "远程IP协议": socket.remoteFamily,
147
+ "id": socket.socketIdxos,
148
+ "进程IP地址": socket.remoteAddress
149
+ })
150
+ if (RetData == undefined) {
151
+ RetData = {}
152
+ }
153
+ if (RetData["是否反馈"] != undefined) {
154
+ if (RetData["是否反馈"] == true) {
155
+ if (RetData["反馈数据"] != "") {
156
+ socket.write(RetData["反馈数据"]);
157
+ }
158
+ }
159
+ }
160
+ if (RetData["是否断开"] != undefined) {
161
+ if (RetData["是否断开"] == true) {
162
+ socket.destroy()
163
+ }
164
+ }
165
+ }
166
+ });
167
+ if (ServerData["是否组包"] == undefined) {
168
+ ServerData["是否组包"] = false
169
+ }
170
+ if (ServerData["是否组包"] == true) {
171
+ socket.setNoDelay(true);
172
+ }
173
+ })
174
+ ServerArr[IntServer].on('close', () => {
175
+ if (MsgFun != undefined) {
176
+ MsgFun({ "状态": "服务器关闭" })
177
+ }
178
+ })
179
+ ServerArr[IntServer].on('drop', () => {
180
+ if (MsgFun != undefined) {
181
+ MsgFun({ "状态": "连接到达上限" })
182
+ }
183
+ })
184
+ ServerArr[IntServer].on('error', () => {
185
+ if (MsgFun != undefined) {
186
+ MsgFun({ "状态": "服务发生错误" })
187
+ }
188
+ })
189
+ return IntServer;
190
+ }
191
+ exports.ServerClose = function (server) {
192
+ if (server == undefined) {
193
+ return;
194
+ }
195
+ try {
196
+ let keys = Object.keys(idObj[server]);
197
+ for (let index = 0; index < keys.length; index++) {
198
+ idObj[server][keys[index]].destroy()
199
+ }
200
+ } catch (error) {
201
+
202
+ }
203
+ ServerArr[server].close(() => {
204
+ try {
205
+ idObj[server] = {};
206
+ } catch (error) {
207
+
208
+ }
209
+ });
210
+ }
211
+ exports.socketList = function (ServerIDInt) {
212
+ let retdata = [];
213
+ if (idObj[ServerIDInt]) {
214
+ for (let key in idObj[ServerIDInt]) {
215
+ retdata[retdata.length] = key;
216
+ }
217
+ return retdata;
218
+ }
219
+ return [];
220
+ }
221
+ exports.send = function (ServerIDInt, id, data) {
222
+ if (idObj[ServerIDInt]) {
223
+ if (idObj[ServerIDInt][id]) {
224
+ idObj[ServerIDInt][id].write(data)
225
+ }
226
+ }
227
+ }
228
+ exports.Disconnect = function (ServerIDInt, id) {
229
+ if (idObj[ServerIDInt]) {
230
+ if (idObj[ServerIDInt][id]) {
231
+ idObj[ServerIDInt][id].destroy()
232
+ }
233
+ }
234
+ }
235
+
236
+
237
+ exports.NewSocket = function (ServerData, MsgFun = undefined) {
238
+ if (ServerData["端口"] == undefined) {
239
+ ServerData["端口"] = 3000
240
+ }
241
+ if (ServerData["地址"] == undefined) {
242
+ ServerData["地址"] = "127.0.0.1"
243
+ }
244
+ ServerArr[ServerArr.length] = null;
245
+ let IntServer = ServerArr.length - 1;
246
+ //2.创建tcp客户端:net.Socket(obj)中可以传入一个obj对象,其属性分别为:fd文件描述、readable是否允许可读、writeable是否可写、allowHalfOpen:false时,tcp服务器接收到客户端发送的fin包后会回发,为true时不回发,前三个属性的默认值为false
247
+ ServerArr[IntServer] = new net.Socket()
248
+ //3.连接tcp服务器:
249
+ ServerArr[IntServer].connect(ServerData["端口"], ServerData["地址"], () => {
250
+ if (MsgFun != undefined) {
251
+ MsgFun({ "状态": "连接服务成功" })
252
+ }
253
+ })
254
+ ServerArr[IntServer].on('data', (dt) => {
255
+ if (MsgFun != undefined) {
256
+ MsgFun({ "状态": "收到数据", "数据内容": dt })
257
+ }
258
+ })
259
+ ServerArr[IntServer].on('end', () => {
260
+ if (MsgFun != undefined) {
261
+ MsgFun({ "状态": "任务完毕" })
262
+ }
263
+ })
264
+ ServerArr[IntServer].on('error', (Error) => {
265
+ if (MsgFun != undefined) {
266
+ MsgFun({ "状态": "发现客户端错误", "错误信息": Error })
267
+ }
268
+ })
269
+ ServerArr[IntServer].on('close', () => {
270
+ if (MsgFun != undefined) {
271
+ MsgFun({ "状态": "客户端被关闭" })
272
+ }
273
+ })
274
+
275
+ return IntServer;
276
+ }
277
+ exports.SocketWrite = function (IntServer, Data) {
278
+ if (IntServer == undefined || Data == undefined) {
279
+ return;
280
+ }
281
+ ServerArr[IntServer].write(Data)
282
+ }
283
+ exports.SocketReadyState = function (IntServer) {
284
+ if (IntServer == undefined) {
285
+ return;
286
+ }
287
+ if (ServerArr[IntServer].readyState == "opening") {
288
+ return "正在连接";
289
+ }
290
+ if (ServerArr[IntServer].readyState == "open") {
291
+ return "连接状态";
292
+ }
293
+ if (ServerArr[IntServer].readyState == "closed") {
294
+ return "断开状态";
295
+ }
296
+ if (ServerArr[IntServer].readyState == "readOnly") {
297
+ return "可读但不可写状态";
298
+ }
299
+ if (ServerArr[IntServer].readyState == "writeOnly") {
300
+ return "不可读写状态";
301
+ }
302
+ return ServerArr[IntServer].readyState;
303
+ }
304
+ exports.SocketDestroy = function (IntServer) {
305
+ if (IntServer == undefined) {
306
+ return;
307
+ }
308
+ ServerArr[IntServer].destroy()
309
+ }
@@ -0,0 +1,78 @@
1
+ const dgram = require('node:dgram');
2
+ let ServerArr = [];
3
+ exports.NewServer = function (port = 22333, MsgFun = undefined) {
4
+ ServerArr[ServerArr.length] = null;
5
+ let IntServer = ServerArr.length - 1;
6
+ ServerArr[IntServer] = dgram.createSocket('udp4');
7
+ // 发生异常时触发
8
+ ServerArr[IntServer].on('error', (err) => {
9
+ if (MsgFun != undefined) {
10
+ MsgFun({ "状态": "发生服务异常", "异常说明": err.stack })
11
+ }
12
+ });
13
+ // 收到消息时触发
14
+ ServerArr[IntServer].on('message', (msg, rinfo) => {
15
+ if (MsgFun != undefined) {
16
+ MsgFun({ "状态": "收到数据", "数据内容": msg, "地址信息": rinfo.address, "端口信息": rinfo.port, "整体信息": rinfo })
17
+ }
18
+ });
19
+ // 启动监听时触发
20
+ ServerArr[IntServer].on('listening', () => {
21
+ const address = ServerArr[IntServer].address();
22
+ if (MsgFun != undefined) {
23
+ MsgFun({ "状态": "启动监听成功", "地址信息": address.address, "端口信息": address.port })
24
+ }
25
+ });
26
+ ServerArr[IntServer].bind(port);
27
+ return IntServer;
28
+ }
29
+ exports.ServerClose = function (IntServer) {
30
+ ServerArr[IntServer].close();
31
+ }
32
+ exports.ServerSend = function (IntServer, data, address, port) {
33
+ ServerArr[IntServer].send(data, port, address)
34
+ }
35
+ exports.NewClient = function (MsgFun = undefined) {
36
+ ServerArr[ServerArr.length] = null;
37
+ let IntServer = ServerArr.length - 1;
38
+ ServerArr[IntServer] = dgram.createSocket('udp4');
39
+ ServerArr[IntServer].on('close', () => {
40
+ if (MsgFun != undefined) {
41
+ MsgFun({ "状态": "关闭客户端" })
42
+ }
43
+ });
44
+ ServerArr[IntServer].on('error', (err) => {
45
+ if (MsgFun != undefined) {
46
+ MsgFun({ "状态": "发生错误异常", "异常说明": err })
47
+ }
48
+ });
49
+ ServerArr[IntServer].on('message', (msg, rinfo) => {
50
+ if (msg == 'exit') {
51
+ if (MsgFun != undefined) {
52
+ MsgFun({ "状态": "接收数据异常" })
53
+ }
54
+ }
55
+ if (MsgFun != undefined) {
56
+ MsgFun({ "状态": "收到数据", "数据内容": msg, "地址信息": rinfo.address, "端口信息": rinfo.port, "整体信息": rinfo })
57
+ }
58
+ });
59
+ if (MsgFun != undefined) {
60
+ MsgFun({ "状态": "初始化UDP成功" })
61
+ }
62
+ return IntServer;
63
+ }
64
+ exports.ClientSend = function (IntServer, message, address, port, MsgFun = undefined) {
65
+ ServerArr[IntServer].send(message, port, address, (err) => {
66
+ if (err) {
67
+ if (MsgFun != undefined) {
68
+ MsgFun({ "状态": "发送数据失败", "错误原因": err })
69
+ }
70
+ }
71
+ if (MsgFun != undefined) {
72
+ MsgFun({ "状态": "发送数据成功" })
73
+ }
74
+ });
75
+ }
76
+ exports.ClientClose = function (IntServer) {
77
+ ServerArr[IntServer].close();
78
+ }