runi95 / turtle-control-panel

A website for monitoring and controlling ComputerCraft turtle activities
13 stars 2 forks source link

Make server ID in portal match the one in database #13

Closed SolsticeSpectrum closed 2 months ago

SolsticeSpectrum commented 2 months ago

This will be useful for the mod I am working on.

runi95 commented 2 months ago

I'm not quite sure what you mean by this, but hopefully this explanation will help:

The server ID in the portal does match the one in the database. If you click on a turtle you should see a URL in your browser that looks something like this: http://localhost:3000/servers/1/turtles/13 where the 1 is the servers.id in the SQLite database and the 13 is the turtles.id in the SQLite database and also the turtle's ID in Minecraft.

If you're talking about the database's primary key then that's a composite primary key meaning you need both the server_id and the id of the turtle.

I might have misunderstood your issue though, so please correct me if I'm wrong / add more information to help me understand the issue at hand.

SolsticeSpectrum commented 2 months ago

For me it shows 9 when it's 1. It's correct in the url but in the list it sometimes says different number

SolsticeSpectrum commented 2 months ago

Oh it's the turtle ID

runi95 commented 2 months ago

Yes, it's the turtle ID and should match with both the turtles.id in the database and the os.getComputerID() in the Minecraft turtle itself. You'll need both the servers.id (server_id) and the turtles.id to get a turtle from the database. That's why both are displayed in the URL as both are needed. With just the servers.id you can only list the turtles on a server.

Compound database primary keys can be a little bit confusing at times especially if you haven't seen or used them before, but I think they make a lot of sense in this use case since you can have multiple servers where the turtles will have the same os.getComputerID() which is what we use to determine which turtle is currently connecting to us.