Introducing: Communicate with a running spring

Introducing: Communicate with a running spring

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Introducing: Communicate with a running spring

Post by Auswaschbar »

Why should I need this?
If your program is interested in certain ingame-events or you want to inject e.g. a chat messages into a running game, then you may use it.

When can I use it?
At this time you can only use this if you are hosting a game, and then you need an svn build >=4100.

How can I activate it?
Its disabled by default. To enable it, you need to do
- start spring with -a[portnum]
or
- set a config variable "Autohost" with positive integer value (=[portnum]) (.springrc on linux, registry on windows)

If -a is set on the commandline, the configuration will be ignored.

How do I use it?
When spring is started like above, it will open a UDP port on the loopback interface and will send some messages to the specified [portnum]. These UDP packets contain the port spring uses so you can send messages in return (will most likely be springs networking portnumber + 10).

What messages will spring send?
A quick reference can be found here
Each message will be send in one single UDP packet. The basic structure is straightforward and looks like:
<unsigned char EVENT_ID><parameter 1><parameter 2><...>
For details of each EVENT_ID see the reference.

What can I send to the engine?
Every packet you will send will be handled like an ingame chat message comming from your player.
This means:
- it will be send to each client
- "a:", "s:" .. can be used
- commands like ".kick xyz" or ".setminspeed x" can be used.

What will be included next?
I currently think of the following:
- support for this at the clients side
- usage of TCP instead of UDP

Please post you criticism / ideas / questions here. :arrow:
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Post by Agon »

What about getting informations from Spring?
Like frames, resource, allys, players, number of units, win/loose condition, map informations.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Post by very_bad_soldier »

Thats amazing! Is this the first step to implement a dedicated server?
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Post by imbaczek »

Agon wrote:allys, players, number of units, win/loose condition, map informations.
This can be found in script.txt.
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Post by Agon »

imbaczek wrote:
Agon wrote:allys, players, number of units, win/loose condition, map informations.
This can be found in script.txt.
But not the live values. What happens if a player leaves, a player changes the team. Okay mapchange is currently not possible. Win/loose conditions could be generated by a lua script.
Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Post by Auswaschbar »

Agon wrote:
imbaczek wrote:
Agon wrote:allys, players, number of units, win/loose condition, map informations.
This can be found in script.txt.
But not the live values. What happens if a player leaves, a player changes the team. Okay mapchange is currently not possible. Win/loose conditions could be generated by a lua script.
If a player leaves there will be a message send. Im not sure but teamchange is not possible.
If the gameend condition would be generated by a LUA script, there is no way of sending it, so this isnt possible.
The ressourcecount would imho encourage cheating.
What do you mean by frames? FPS or in-game-frames? Why do you need them? Informing about in-game-frames would mean ~25 packets per second. FPS or the CPU-usage could be usefull
User avatar
Agon
Posts: 527
Joined: 16 May 2007, 18:33

Post by Agon »

FPS=Frames per second. Only send one package in one second that has the value: all frames of one second / amount of frames in one second.
User avatar
Michilus_nimbus
Posts: 634
Joined: 19 Nov 2004, 20:38

Post by Michilus_nimbus »

I'm making a test script as I speak :-)
User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Introducing: Communicate with a running spring

Post by Licho »

How do I start spring if I want to set both port (using commandline) and path to script.txt?

There can be many springies on one system so storing autohost in registry is not usefull. And since many springies are using same spring folder, they also need to specify different paths to script.txt
User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Introducing: Communicate with a running spring

Post by Licho »

Also I need some way to gracefully exit game. So probably some ".quit" command. If you can make it, I would be gratefull.
(I can just kill the spring process but I dont consider it very clean)
User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Introducing: Communicate with a running spring

Post by Licho »

Also I encountered some bug:

Game only has host (spectator) and a player.
It starts (and ends instantly) but both people stay in game.
If I now try to send a chat inject packet to spring, it start spamming:
Got invalid player num 255 in chat msg

In endless cycle (even back to listenening autohost)
Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Re: Introducing: Communicate with a running spring

Post by Auswaschbar »

Licho wrote:How do I start spring if I want to set both port (using commandline) and path to script.txt?
Simple:
spring -a <port> /path/to/script (linux)
spring /a <port> /path/to/script (not sure, but should be this on windows)
Licho wrote:Also I encountered some bug:

Game only has host (spectator) and a player.
It starts (and ends instantly) but both people stay in game.
If I now try to send a chat inject packet to spring, it start spamming:
Got invalid player num 255 in chat msg

In endless cycle (even back to listenening autohost)
Sound like you are using 0.76b1 version, right? Its known bug and already fixed in svn.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Introducing: Communicate with a running spring

Post by AF »

Any progress on a human readable format that doesn't read/work like a bitfield?
User avatar
LordMatt
Posts: 3393
Joined: 15 May 2005, 04:26

Re: Introducing: Communicate with a running spring

Post by LordMatt »

Edited OP to unbreak forum, however the offending link is to osrts.info and is now dead.
User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Introducing: Communicate with a running spring

Post by Licho »

Auswaschbar wrote: spring /a <port> /path/to/script (not sure, but should be this on windows)
This doesnt work :(
If I specify any param (like /a port or -a port) it then ignores path to script..

I would use registry but I run into problem when you try to autohost and play on your own autohost ..
Either both client and host or none of them then read autohost registry settings.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Introducing: Communicate with a running spring

Post by AF »

You also forgot that java can't natively access any arbitrary registry value either.

Ideally this should be a script.txt parameter not a global setting.
User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Introducing: Communicate with a running spring

Post by Licho »

Yeah putting that to script.txt would be best I guess
Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Re: Introducing: Communicate with a running spring

Post by Auswaschbar »

Licho wrote:This doesnt work :(
If I specify any param (like /a port or -a port) it then ignores path to script..
Fixed, windows commandline parsing needs extra options to work with parameters. I Forgot that.
Licho wrote:Yeah putting that to script.txt would be best I guess
I don't like the idea of putting unsynced and not-really-game-related stuff in the startscript / gamesetup. Would this have any advantages over current way with commandline parameters?
AF wrote:Any progress on a human readable format that doesn't read/work like a bitfield?
No bitfield, just plain binary data. And no, no progress here. Its not intended for humans, so why doing extra work converting it to ascii-text?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Introducing: Communicate with a running spring

Post by AF »

Using the same set of arguments we can take out about 20 tags from script.txt, player ranks? Host IP? Host port? client ports? Adding it as a command line parameter is inconsistent and incompetent API design.
No bitfield, just plain binary data. And no, no progress here. Its not intended for humans, so why doing extra work converting it to ascii-text?
The point being it should have been in that ascii format to begin with. And it should be human readable for debugging purposes, and to make development a lot easier. This is a local feedback loop, there's no bandwidth issue here. I would rather have a string rather than a mishmash of strings and binary values which could be problematic due to character set issues.

For one how do you handle integers? Do you just bung them into the packet as is? How am I supposed to handle them under 64bit linux? Did you know integers in *nix x64 are 64bit but 32bit in 64bit windows? Signed or unsigned?

Please remember auwaschbar, one of the most important parts of API design is that you design for your users, and right now your target audience is being dismissed out of hand. Criticisms are being ignored and the only thing your actually bothering to do anything about is bug reports in what's already there.

Did it not occur to you that lobby developers may wish to use this? Especially when the whole point of doing it was to make it easier for auto hosts to do something that we lobby developers have been trying to do too?!?!? Especially when there were already bug reports involving my efforts to do it in AFLobby and efforts by other people in the lobby at the time?

You do realize that the vast majority of criticisms and problems levied against you were easily avoided entirely from the beginning by asking the people who would actually use it in the end?

Now in further review of the thread
  • Where is this reference? There are no links in the original post.
  • Unicode? ASCII? UTF-8?
  • Lua<->Lobby?
  • Game Time?/Frame number?
Auswaschbar
Spring Developer
Posts: 1254
Joined: 24 Jun 2007, 08:34

Re: Introducing: Communicate with a running spring

Post by Auswaschbar »

AF wrote:Using the same set of arguments we can take out about 20 tags from script.txt, player ranks? Host IP? Host port? client ports? Adding it as a command line parameter is inconsistent and incompetent API design.
I never designed an API before, so I didn't took this into account. And I just made an "AutohostPort" option for the script.
AF wrote:For one how do you handle integers? Do you just bung them into the packet as is? How am I supposed to handle them under 64bit linux? Did you know integers in *nix x64 are 64bit but 32bit in 64bit windows? Signed or unsigned?
I used the same method like normal spring networking, which just assumed that integers are 4-byte in size. I wonder how spring works in 64-bit linux when the integers are bigger :roll:
AF wrote:Please remember auwaschbar, one of the most important parts of API design is that you design for your users, and right now your target audience is being dismissed out of hand. Criticisms are being ignored and the only thing your actually bothering to do anything about is bug reports in what's already there.
I don't ignore criticism. But I don't consider "Do it like this!" criticism, thats why I asked you to give some arguments.
And I know that the whole interface-thingie is currently not easy to maintain, hard to expand and inflexible. Thats why I am redesigning it to support different protocols, other ways of transport (network, file, stdout...) etc. So I am actually doing stuff, there is no need to insult anyone.
AF wrote:Where is this reference? There are no links in the original post.
LordMatt wrote:Edited OP to unbreak forum, however the offending link is to osrts.info and is now dead.
-> reference
AF wrote:Unicode? ASCII? UTF-8?
ASCII
AF wrote:Lua<->Lobby?
Not sure if it was that what you thought of, but I could forward the custom Lua-Messages if it would be usefull.
AF wrote:Game Time?/Frame number?
Do you want them to be sent constantly (e.g. every x frames / seconds) or only after request?
Post Reply

Return to “Engine”