ropenttd / gopenttd Goto Github PK
View Code? Open in Web Editor NEW馃幃 A library for interacting with OpenTTD game servers.
License: MIT License
馃幃 A library for interacting with OpenTTD game servers.
License: MIT License
Hi, thanks for making this it looks really good and I'd love to use it but I'm running into some trouble
When I open a session my CPU usage on a single core jumps to 100%,
Also I have some handlers but only the very first date event is triggered none of the others seem to be working, this is my code:
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/ropenttd/gopenttd/pkg/admin"
"github.com/ropenttd/gopenttd/pkg/util"
)
func main() {
sess, err := admin.New("127.0.0.1", 3977, "admin123")
if err != nil {
panic(err)
}
err = sess.Open()
if err != nil {
panic(err)
}
sess.AddHandler(clientJoin)
sess.AddHandler(getDate)
sess.AddHandler(onMessage)
// Wait here until CTRL-C or other term signal is received.
fmt.Println("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}
func getDate(sess *admin.Session, d *admin.Date) {
fmt.Println(util.DateFormat(d.CurrentDate))
}
func clientJoin(sess *admin.Session, d *admin.ClientJoin) {
fmt.Println("Meow")
}
func onMessage(sess *admin.Session, d *admin.Chat) {
fmt.Println("Message sent")
}
It's meant to print Meow or Message Sent when someone sends a chat message or joins the server, it should also print the current date whenever it's triggered but the only output is a single Current Date:
Starting: /home/baa/go/bin/dlv-dap dap --check-go-version=false --listen=127.0.0.1:42275 --log-dest=3 from /home/baa/Documents/Dev/OpenTTD-Discord-Bot
DAP server listening at: 127.0.0.1:42275
Type 'dlv help' for list of commands.
Bot is now running. Press CTRL-C to exit.
1991-01-05 00:00:00 +0000 UTC
With OpenTTD/OpenTTD#10709 company shares have been removed, including from he admin packet with an increment of the protocol version number.
I'm not sure what is going to happen, since I have not set up go
and as such can't run the code. However, I suspect it's either bailing out because the packet does not have enough information for the decoding to complete, or it's returning the company with id 0 as owner of all the shares. The latter might trip up users of this library, as it might think that company 0 owns a lot of other companies.
gopenttd/pkg/admin/packets/packets_server.go
Lines 275 to 278 in ccf1a51
This is very odd, but if you request that UpdateTypeClientInfo
is set to UpdateFrequencyAutomatically
ie:
sess.RequestUpdates(enum.UpdateTypeClientInfo, enum.UpdateFrequencyAutomatically)
and then query server info, by either viewing the server in OpenTTD Multiplayer List or clicking the Refresh server
gopenttd will Panic with:
"reflect.Set: value of type uint8 is not assignable to type enum.NetE...
Stack:
2 0x00000000004a4ad1 in reflect.Value.assignTo
at /snap/go/current/src/reflect/value.go:2797
3 0x00000000004a1a32 in reflect.Value.Set
at /snap/go/current/src/reflect/value.go:1905
4 0x000000000075d51e in github.com/ropenttd/gopenttd/pkg/admin.ottdUnmarshalData
at /home/baa/go/pkg/mod/memleak.eu/sn0w/[email protected]/pkg/admin/proto_unmarshal.go:46
5 0x000000000075d0b8 in github.com/ropenttd/gopenttd/pkg/admin.ottdUnmarshal
at /home/baa/go/pkg/mod/memleak.eu/sn0w/[email protected]/pkg/admin/proto_unmarshal.go:26
6 0x000000000075c2c5 in github.com/ropenttd/gopenttd/pkg/admin.(*Session).onEvent
at /home/baa/go/pkg/mod/memleak.eu/sn0w/[email protected]/pkg/admin/proto_api.go:419
7 0x000000000075b42b in github.com/ropenttd/gopenttd/pkg/admin.(*Session).listen
at /home/baa/go/pkg/mod/memleak.eu/sn0w/[email protected]/pkg/admin/proto_api.go:287
8 0x000000000075a1c7 in github.com/ropenttd/gopenttd/pkg/admin.(*Session).Open路dwrap路10
at /home/baa/go/pkg/mod/memleak.eu/sn0w/[email protected]/pkg/admin/proto_api.go:108
I find that setting type NetError uint8
to type NetError int8
under pgk/enum/constants.go resolves the issue... but I'm not sure if that's correct or not: https://memleak.eu/sn0w/gopenttd/commit/63e5c696f0cd942a7b7388881e08f95225ce88ac
A declarative, efficient, and flexible JavaScript library for building user interfaces.
馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google 鉂わ笍 Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.