Network Protocol For Bots [v3]

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
dihedral
Tycoon
Tycoon
Posts: 1053
Joined: 14 Feb 2007 17:48

Network Protocol For Bots [v3]

Post by dihedral »

I have been working on a separate network protocol, specifically for bots to join and do their thing.
(as bots do not need to download the map, they have no chance of getting hold of it :-P)

It allows up to 16 bots (MAX_BOTS) to connect. Each bot needs to "register" the updates (BotUpdateType) it wants to receive at a desired frequency (BotUpdateFrequency), however, polling (BOTPACKET_BOT_POLL) is also supported.

The protocol is designed to not disconnect bots when they have sent wrong packets, instead they will be prompted with a packet named BOTPACKET_SERVER_NOT_SUPPORTED which holds details of the packet the bot sent causing the error.

Feel free to mention protocol additions / changes, in case you find data you would like bots to be able to get hold of.

Note: Influencing Industries and/or Towns is not scope of this thread.

Following config file additions to be watched out for:
network.server_bot_port, the port the bot network will open for incoming bot connections, defaults to 3977
network.server_bot_chat, allow private chat to the server to be also distributed to bots
network.bot_password, bots can only join if a password is set. not password, no bots!

As bots are required to join with a password, the bot's rcon command packet does not require any additional passwords to be sent.

Update Types are bound to possible Update Frequencies, all Update Types allow UPDATE_FREQUENCY_NONE:
BOT_UPDATE_DAILY supports also the Frequencies: Daily, Weekly, Monthly, Quarterly, Anually
BOT_UPDATE_CLIENT_INFO supports also the Frequency: Automatic
BOT_UPDATE_COMPANY_INFO supports also the Frequency: Automatic
BOT_UPDATE_COMPANY_ECONOMY supports also the Frequencies: Weekly, Monthly, Quarterly, Anually
BOT_UPDATE_COMPANY_STATS supports also the Frequencies: Weekly, Monthly, Quarterly, Anually
BOT_UPDATE_CHAT supports also the Frequency: Automatic
BOT_UPDATE_CONSOLE supports also the Frequency: Automatic

Update types bots can register

Code: Select all

enum BotUpdateType {
	BOT_UPDATE_DATE,
	BOT_UPDATE_CLIENT_INFO,
	BOT_UPDATE_COMPANY_INFO,
	BOT_UPDATE_COMPANY_ECONOMY,
	BOT_UPDATE_COMPANY_STATS,
	BOT_UPDATE_CHAT,
	BOT_UPDATE_CONSOLE,
	BOT_UPDATE_END
};
Update Frequencies

Code: Select all

enum BotUpdateFrequency {
	BOT_FREQUENCY_NONE      = 0x01,
	BOT_FREQUENCY_DAILY     = 0x02,
	BOT_FREQUENCY_WEEKLY    = 0x04,
	BOT_FREQUENCY_MONTHLY   = 0x08,
	BOT_FREQUENCY_QUARTERLY = 0x10,
	BOT_FREQUENCY_ANUALLY   = 0x20,
	BOT_FREQUENCY_AUTOMATIC = 0x40,
	BOT_FREQUENCY_END       = 0x80
};
Packet Types

Code: Select all

enum TCPBotPacketType {
	BOTPACKET_SERVER_FULL,
	BOTPACKET_SERVER_ERROR,
	BOTPACKET_BOT_JOIN,
	BOTPACKET_SERVER_WELCOME,
	BOTPACKET_BOT_DATE,
	BOTPACKET_SERVER_DATE,
	BOTPACKET_SERVER_CLIENT_JOIN,
	BOTPACKET_SERVER_CLIENT_INFO,
	BOTPACKET_SERVER_CLIENT_UPDATE,
	BOTPACKET_SERVER_CLIENT_QUIT,
	BOTPACKET_SERVER_CLIENT_ERROR,
	BOTPACKET_SERVER_COMPANY_NEW,
	BOTPACKET_SERVER_COMPANY_INFO,
	BOTPACKET_SERVER_COMPANY_UPDATE,
	BOTPACKET_SERVER_COMPANY_ECONOMY,
	BOTPACKET_SERVER_COMPANY_STATS,
	BOTPACKET_SERVER_COMPANY_REMOVE,
	BOTPACKET_BOT_UPDATE_FREQUENCY,
	BOTPACKET_BOT_POLL,
	BOTPACKET_BOT_CHAT,
	BOTPACKET_SERVER_CHAT,
	BOTPACKET_SERVER_NEWGAME,
	BOTPACKET_SERVER_SHUTDOWN,
	BOTPACKET_BOT_QUIT,
	BOTPACKET_BOT_RCON,
	BOTPACKET_SERVER_RCON,
	BOTPACKET_SERVER_NOT_SUPPORTED,
	BOTPACKET_SERVER_PROTOCOL,
	BOTPACKET_SERVER_CONSOLE,
	BOTPACKET_END                ///< Must ALWAYS be on the end of this list!! (period)
};
The connection procedure is:

Bot sends BOTPACKET_BOT_JOIN
(if the limit of joined bots has been reached, the server will send BOTPACKET_SERVER_FULL and close the connection)
(if the password is wrong, the server will send BOTPACKET_SERVER_ERROR and disconnect the bot)
Server sends BOTPACKET_SERVER_PROTOCOL
Server sends BOTPACKET_SERVER_WELCOME

(it is up to the bot to decide weather or not it can handle the bot protocol version mentioned in the BOTPACKET_SERVER_PROTOCOL packet)

As of here the bot is free to register for update packets, or to poll data and do what it would like to do.

Please read the patch in order to understand the structure of the separate packets.
Attachments
botspec_r20853.3.diff
(57.35 KiB) Downloaded 124 times
Last edited by dihedral on 26 Sep 2010 19:34, edited 1 time in total.
dihedral
Tycoon
Tycoon
Posts: 1053
Joined: 14 Feb 2007 17:48

Re: Network Protocol For Bots [v3]

Post by dihedral »

Update:

Feature:
- New update packet: BOT_UPDATE_CONSOLE (sends BOTPACKET_SERVER_CONSOLE packets)
Sends whatever would be printed to the servers console (currently except debug messages).

Fixes:
- Using rcon to execute 'say' commands would recurse back to all bots
- Replies from rcon were not colour stripped (now uses the same string as known from the dedicated server console)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 12 guests