Skip to content

Commit

Permalink
fix HandshakeEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Oct 22, 2023
1 parent 7eca6bf commit 6dfda60
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cmds/liter-server/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,11 @@ type ServerIns struct {
Target string `json:"target" yaml:"target"`
ServerNames []string `json:"names" yaml:"names"`
// HandlePing is useful if you want to hide online players from others who won't join the server
HandlePing bool `json:"handle-ping" yaml:"handle-ping"`
HandlePing bool `json:"handlePing" yaml:"handle-ping"`
// Motd only use when HandlePing is true
Motd string `json:"motd" yaml:"motd"`
// MotdFailed will be send back when the ping connection failed on the server
MotdFailed string `json:"motd-failed" yaml:"motd-failed"`
MotdFailed string `json:"motdFailed" yaml:"motd-failed"`
}

func getServers()(servers []*ServerIns, listHash string){
Expand Down
2 changes: 1 addition & 1 deletion cmds/liter-server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *Server)handle(c *liter.Conn, cfg *Config){
noforward := <-s.scripts.Emit(script.NewEvent("handshake", Map{
"client": wc.Exports(),
"handshake": hp,
"target": &svr, // to allow changes to the target
"target": *svr, // do not allow changes
}))
if wc.Closed() {
return
Expand Down
45 changes: 31 additions & 14 deletions script/types/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ declare global {
error(...args: any[]): void
}

function setInterval(handler: Function, timeout?: number, ...arguments: any[]): Object
function setTimeout(handler: Function, timeout?: number, ...arguments: any[]): Object
function setImmediate(handler: Function, ...arguments: any[]): Object
function clearInterval(id: Object | undefined): void
function clearTimeout(id: Object | undefined): void
function clearImmediate(id: Object | undefined): void
function setInterval(handler: Function, timeout?: number, ...arguments: any[]): Readonly<Object>
function setTimeout(handler: Function, timeout?: number, ...arguments: any[]): Readonly<Object>
function setImmediate(handler: Function, ...arguments: any[]): Readonly<Object>
function clearInterval(id: Readonly<Object> | undefined): void
function clearTimeout(id: Readonly<Object> | undefined): void
function clearImmediate(id: Readonly<Object> | undefined): void

type Event<T extends obj = Object> = _Event<T> & T

Expand Down Expand Up @@ -105,17 +105,34 @@ declare global {
json<T>(): T
}

interface HandshakePkt {
protocol: number
addr: string
addition: string
port: number
nextState: number
}

interface ServerIns {
id: string
target: string
serverNames: string[]
handlePing: boolean
motd: string
motdFailed: string
}

type HandshakeEvent = Event<{
client: Conn
handshake: Readonly<HandshakePkt>
target: Readonly<ServerIns>
}>

type ServeEvent = Event<{
player?: PlayerInfo
player?: PlayerInfo // undefined means serve for ping connection
client: Conn
server: Conn
handshake: {
protocol: number
addr: string
addition: string
port: number
nextState: number
}
handshake: Readonly<HandshakePkt>
}>

type PacketEvent = Event<{
Expand Down
2 changes: 1 addition & 1 deletion script/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "go-liter-plugin",
"version": "1.0.2",
"version": "1.0.3",
"description": "Typescript definitions for Go Liter script",
"types": "./lib/index.d.ts",
"scripts": {
Expand Down

0 comments on commit 6dfda60

Please sign in to comment.