-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Archipelago WIP #31
base: main
Are you sure you want to change the base?
Archipelago WIP #31
Changes from 192 commits
a98cab5
3c992f5
d646d8a
4548ff6
e4cb574
027a9e7
bffb161
5e49b5a
1c2c3d2
5462c4a
27398bd
41c48cf
2e399c4
4d248c8
537ad3f
69e444d
d26cb7c
fadab6b
98f9b51
f54c46e
dec3d90
0e9b84a
9e6b414
6aff5fa
abb8038
3d2dba4
26341e8
2b05a63
bed4ab5
1f1c0c7
44f84e0
2f3df74
33b0b1a
b11eec6
6c78149
66f11cc
d0cf68d
72f5467
1ec768d
e408dd7
c22c329
30792f3
2b2fc66
0792177
c08f291
c22375a
13d7644
c1a81d4
5fd4678
b0bbeb2
fd889e9
0e81da2
4ffd127
e28445e
095322e
7d9929d
0e9f21d
ecda737
7019f57
a077492
aee22b7
b9df067
0ea821c
1b27102
3d1616b
d494da9
da103e9
a2ddb8f
8391f1d
929c32a
297bbbc
8b119b7
dd47555
ac94319
0180149
cfaa309
55d376e
b5f1a13
bba7a73
ebff71f
d18476c
f12f02f
da1c9a5
e753d98
6f11931
4a393f6
e656e81
84e3710
295b387
94dea55
f4fd0f1
b039765
856b53a
137c773
6661105
3c88406
edf2d97
4c2138e
a908d5b
2d7e116
08a3216
42ffb31
db3991e
4952984
215ba1f
ace8ef3
77518cf
7d645a0
be41ec6
5ae8521
2c25e84
a2182ab
b2fb735
6a543e6
0f991d5
f104792
56845f9
6f15c2e
cb84f96
df12270
af7a91a
f9975f0
b4a2a5c
e614c91
10a749b
8d045e1
bfe85e1
0f36a1c
77fe706
98b2c6f
4c4ab9a
741c6b9
427cca0
a621988
a04beb6
4f5aa9a
9138398
c9f44b9
b354982
8e406d7
170c9e7
f6a607c
de3be86
961a34c
2065347
4983239
0025e06
2de040f
f717ecf
5c7b103
9c1b500
721bb52
7284a9c
0c05f4f
bc510ca
aced274
caa5f2d
65c16f4
8813adc
2ba9c2a
04c8dab
9054c70
17f9ce2
f9e4c51
3bd519e
1563d26
1fc3fcd
a09e06d
b11b0af
1d275ae
ba25ca6
dd5db2a
329b7c7
081d42f
708c492
634d5fe
8fb7516
8cb7b07
9374099
51714df
0b2eca7
b7efb67
067108c
99a0442
9c6bfc0
532ceae
e67b1c5
371b853
56d13b2
5f21fc5
5b085a8
5649f57
3836ad8
b3647a5
0309124
64dbecd
041da9e
13d167a
262b498
2e9f929
1305409
83098fa
aaca47b
47b0ed4
2e1723a
098daba
7787af2
93424df
804d5b7
07458c9
327963f
7fd5e07
0b6fae4
0c1ec2d
4192ca4
58e574b
4d4cfec
7693e65
59b9e18
9af1e75
2a0309e
89eaf0b
fa24f83
c97eedd
5adf4e3
7cf0a9d
706ef4b
69f78ea
4356406
09411c6
8349811
5d69e8f
0d836a5
a56491f
b83c5f5
1d5eca8
e39aab6
fecbec6
7534d46
d78ad7a
ac4ddad
cd08b30
c70345b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"overrides": [ | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,3 +105,4 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
FormatCodes.cpp |
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this .park file too |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,219 @@ | ||||||
|
||||||
class APIConnection | ||||||
{ | ||||||
sock:Socket = null; | ||||||
good: boolean = false; | ||||||
reconnect_interval: number = null; | ||||||
name:string = "API"; | ||||||
port:number; | ||||||
callback:CallableFunction; | ||||||
errorCallback:CallableFunction; | ||||||
connectCallback:CallableFunction; | ||||||
onCloseCallback: (hadError: any) => void; | ||||||
onExpectedCloseCallback: (hadError: any) => void; | ||||||
onErrorCallback: (hadError: any) => void; | ||||||
onDataCallback: (hadError: any) => void; | ||||||
buffer:string = ""; | ||||||
|
||||||
constructor(name:string, port:number, callback:CallableFunction, errorCallback?:CallableFunction, connectCallback?:CallableFunction) { | ||||||
this.name = name; | ||||||
this.port = port; | ||||||
this.callback = callback; | ||||||
this.errorCallback = errorCallback; | ||||||
this.connectCallback = connectCallback; | ||||||
|
||||||
var self = this; | ||||||
this.onCloseCallback = function(hadError){self.onClose(hadError);}; | ||||||
this.onExpectedCloseCallback = function(hadError){self.onExpectedClose(hadError);} | ||||||
this.onErrorCallback = function(hadError){self.onError(hadError);}; | ||||||
this.onDataCallback = function(hadError){self.onData(hadError);}; | ||||||
|
||||||
this.connect(); | ||||||
} | ||||||
|
||||||
send(data:Object) { | ||||||
try { | ||||||
let r: string = JSON.stringify(data) + '\0'; | ||||||
info(this.name+' sending:', r.length, r); | ||||||
this.end(r); | ||||||
} catch(e) { | ||||||
printException('error sending '+this.name, e); | ||||||
} | ||||||
} | ||||||
|
||||||
destroy() { | ||||||
if(!this.sock) return; | ||||||
|
||||||
info(this.name+'.destroy()'); | ||||||
try { | ||||||
this.sock.off('close', this.onCloseCallback); | ||||||
} catch(e) { | ||||||
printException('error closing event handlers in '+this.name+'.close', e); | ||||||
} | ||||||
|
||||||
try { | ||||||
this.sock.off('close', this.onExpectedCloseCallback); | ||||||
} catch(e) { | ||||||
printException('error closing event handlers in '+this.name+'.close', e); | ||||||
} | ||||||
|
||||||
try { | ||||||
this.sock.destroy(null); | ||||||
} catch(e) { | ||||||
printException('error destroying old '+this.name+' connection ', e); | ||||||
} | ||||||
|
||||||
this.sock = null; | ||||||
} | ||||||
|
||||||
private onError(hadError: boolean) { | ||||||
info('error in '+this.name+' connection, will keep trying...'); | ||||||
if(this.good) { | ||||||
park.postMessage( | ||||||
{type: 'blank', text: 'error in '+this.name+' connection, will keep trying...'} as ParkMessageDesc | ||||||
); | ||||||
} | ||||||
if(this.errorCallback) { | ||||||
this.errorCallback(); | ||||||
} | ||||||
this.good = false; | ||||||
this.connect(); | ||||||
} | ||||||
|
||||||
private onClose(hadError: boolean) { | ||||||
info(this.name+' connection closed, will keep trying...'); | ||||||
if(this.good) { | ||||||
park.postMessage( | ||||||
{type: 'blank', text: this.name+' connection closed, will keep trying...'} as ParkMessageDesc | ||||||
); | ||||||
} | ||||||
this.good = false; | ||||||
this.connect(); | ||||||
} | ||||||
|
||||||
private onExpectedClose(hadError: boolean) { | ||||||
info(this.name+' connection closed cc_onExpectedClose, will keep trying...'); | ||||||
this.good = true; | ||||||
this.connect(); | ||||||
} | ||||||
|
||||||
private reconnect() { | ||||||
debug(this.name+' reconnecting...'); | ||||||
this.connect(); | ||||||
} | ||||||
|
||||||
private onData(message: string) { | ||||||
let data: Object = null; | ||||||
let resp: Object = null; | ||||||
|
||||||
let packets = message.split('\0') | ||||||
message = packets[0]; | ||||||
|
||||||
// try | ||||||
try { | ||||||
data = JSON.parse(message); | ||||||
this.buffer = ""; | ||||||
} catch(e) { | ||||||
try { | ||||||
this.buffer += message; | ||||||
data = JSON.parse(this.buffer); | ||||||
this.buffer = ""; | ||||||
} | ||||||
catch(e) { | ||||||
printException('error parsing '+this.name+' request JSON: ' + message, e); | ||||||
return; | ||||||
} | ||||||
} | ||||||
|
||||||
try { | ||||||
info(this.name+" received data: ", data); | ||||||
resp = this.callback(data); | ||||||
// this.send(resp); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like this needs to be uncommented? maybe checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s been a couple months, but to my memory, sending the response immediately seemed to break the connection and error out the client. Uncommenting it always seems to break the program the moment a package is received. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} catch(e) { | ||||||
printException('error handling '+this.name+' request: ' + message, e); | ||||||
} | ||||||
|
||||||
if(packets.length > 1) { | ||||||
packets = packets.slice(1); | ||||||
message = packets.join('\0'); | ||||||
if(message.length > 1) { | ||||||
this.onData(message); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
private reset_timeout() { | ||||||
if(this.reconnect_interval !== null) { | ||||||
context.clearInterval(this.reconnect_interval); | ||||||
this.reconnect_interval = null; | ||||||
} | ||||||
|
||||||
//this.reconnect_interval = context.setInterval(this.end, 5000); | ||||||
} | ||||||
|
||||||
private end(data?:string) { | ||||||
if(!this.sock) return; | ||||||
|
||||||
info(this.name+'.end()'); | ||||||
try { | ||||||
this.sock.off('close', this.onCloseCallback); | ||||||
this.sock.on('close', this.onExpectedCloseCallback); | ||||||
} catch(e) { | ||||||
printException('error closing event handlers in '+this.name+'.close', e); | ||||||
} | ||||||
|
||||||
try { | ||||||
data = data ? data : '{"id": 0, "status": 0}\0'; | ||||||
info(this.name+'.sock.end('+data+')'); | ||||||
this.sock.end(data); | ||||||
} catch(e) { | ||||||
printException('error closing old '+this.name+' connection ', e); | ||||||
} | ||||||
|
||||||
try { | ||||||
this.sock.destroy(null); | ||||||
} catch(e) { | ||||||
printException('error destroying old '+this.name+' connection ', e); | ||||||
} | ||||||
|
||||||
this.reset_timeout(); | ||||||
this.good = true; | ||||||
} | ||||||
|
||||||
private connect() { | ||||||
var self = this; | ||||||
|
||||||
if (network.mode == "server") { | ||||||
//info("This is a server..."); | ||||||
} else if (network.mode == "client") { | ||||||
//info("This is a client..."); | ||||||
return; | ||||||
} else { | ||||||
//info("This is single player..."); | ||||||
} | ||||||
|
||||||
this.reset_timeout(); | ||||||
this.destroy(); | ||||||
|
||||||
info(this.name+'.connect'); | ||||||
this.sock = network.createSocket(); | ||||||
|
||||||
this.sock.connect(this.port, '127.0.0.1', function() { | ||||||
if(!self.good) { | ||||||
info(self.name+' connected to port '+self.port); | ||||||
park.postMessage( | ||||||
{type: 'blank', text: self.name+' connected!'} as ParkMessageDesc | ||||||
); | ||||||
if(self.connectCallback) { | ||||||
self.connectCallback(); | ||||||
} | ||||||
} | ||||||
self.good = true; | ||||||
}); | ||||||
this.sock.setNoDelay(true); | ||||||
|
||||||
this.sock.on('error', this.onErrorCallback); | ||||||
this.sock.on('close', this.onCloseCallback); | ||||||
this.sock.on('data', this.onDataCallback); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need these .park files in the repo? what are they for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can probably move these to the release. They're the custom maps specifically made for Archipelago