BattleHub Scripting

BattleHub Scripting

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

Moderator: Moderators

Post Reply
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

BattleHub Scripting

Post by AF »

At the moment I am looking for ways of making BattleHub extensible, and Im wondering what languages people are interested in?

Im particularly drawn to JRuby but I don't know how people will feel about that..
Last edited by AF on 08 Jul 2008, 22:24, edited 1 time in total.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Lobby Scripting

Post by aegis »

python > ruby

if we defined a standard scripting interface, we could easily use the same scripts in multiple lobbies. there is a python unit for delphi, wxscript can interface with python, and my lobby can natively use python
since spring already depends on python, it will at least have the interpreter dll

I would probably also write copious quantities of useful scripts if we had a python scripting interface for lobbies
</fanboi>
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lobby Scripting

Post by AF »

Well I have javascript and ruby interfaces already, Ill have a look into jython.
However for the moment I'm not too bothered about lobby standards as the scripts would be instantiating java objects and communicating with java objects, and a lot of the APIs and features available wont make sense in other lobbies.

For example inserting buttons smilies and images into chat text only makes sense in my lobby which is the only lobby so far to support it.

That said if it were put forward I wouldn't mind adding support for any additional standardized scripting interfaces that are discussed here.

hmmm the jython website only provides an installer, and Im not so sure how Id go about embedding it in battlehub.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Lobby Scripting

Post by aegis »

abstraction is good in a scripting interface; playing with java in your interpreted language is ugly

the interface would need to provide:
  • a way to register a handler for protocol events (i.e. SAID, OPENEDBATTLE, SAY, etc), both incoming and outgoing
  • functions to handle common lobby actions and to access information (current channels, users, battles, lobby capabilities, etc)
  • functions to handle specific lobby actions - scripts can disable certain functionality or refuse to run entirely if the lobby doesn't support it (like your smiley example)
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Lobby Scripting

Post by aegis »

check Demo/embed/ after installing jython
User avatar
quantum
Posts: 590
Joined: 19 Sep 2006, 22:48

Re: Lobby Scripting

Post by quantum »

Lua! Lots of coders involved with Spring know how to use it.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Lobby Scripting

Post by aegis »

C! Lots of coders involved with Spring know how to use it.

interface specification draft:

protocol handling:
  • handleIncoming( event, handler )
  • handleOutgoing( event, handler )
lobby actions:
  • modify server list
  • rename account
  • change password
  • hash password
  • join/leave/host battle
  • send messages
  • format text
specific lobby actions:
  • make smilies
  • more stuff
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lobby Scripting

Post by AF »

luajava requires the usage of a native binary which could greatly complicate the deployment of battlehub, whereas JRuby and Jython are pure java.

But as I said, abstraction would take my 3 day ETA and turn it into a 30 day ETA, and I have other features to be getting on with.
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Re: Lobby Scripting

Post by Dragon45 »

Just define a good abstract interface for start
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Lobby Scripting

Post by imbaczek »

java 6 has a javascript interpreter in the standard distribution, right? might as well use that.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lobby Scripting

Post by AF »

Ive got jython working anyway
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Lobby Scripting

Post by AF »

SLI and SLO make no sense in the context of the warzone2100 ta3d OTA and glest communities.

Any scripting would also make hefty use of OO
Satirik
Lobby Developer
Posts: 1688
Joined: 16 Mar 2007, 18:27

Re: Lobby Scripting

Post by Satirik »

LI ... LO ?
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Lobby Scripting

Post by aegis »

I will provide python code for handling each raw protocol event from the server

a lobby will simply need two function calls hooking into the handler

one will be when the lobby receives a protocol event, before it handles it itself
it will pass the entire line from the server to the python function and receive it back, modified or unmodified
it will parse the line it receives from the python handler instead of the line it received from the server, and not parse at all if it receives a blank string

psuedo code example

Code: Select all

data = recieveDataFromServer()
data = pythonParseDataFromServer(data)
locallyHandleData(data)
the same applies to sending data
before sending data to a socket, you send it to the python handler
and send the string the python handler returned instead of what you would have sent

psuedo code example

Code: Select all

dataToSend = pythonParseDataFromServer(dataToSend)
sendData(data)
another interface the python scripting will need abstracted is a simple way to add configuration options in the lobby

so you can call a function to enable a configuration tab for the script, then add checkboxes, input fields, etc
then give api functions to get these custom config options
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Lobby Scripting

Post by aegis »

Scripting is currently working at a basic level.

API draft:

Code: Select all

import lobbyscript
api = lobbyscript.Callback()
api.function()
Functions the lobby must call in the handler:
  • handleIn( string data )
    Handles each line of incoming protocol. the lobby processes whatever data the function returns instead of the data received from the server
  • handleOut( string data )
    Handles each line of outgoing protocol, the lobby sends whatever this function returns instead of the original string
  • onDisconnect()
    Lobby calls before closing the socket to disconnect from the server
  • onClose()
    Lobby calls before exiting, after the socket has been closed
Functions provided by the callback API:
  • Meta commands:
  • LoadScripts()
    Invoke's the handler's _load() function (no arguments) which loads any new modules which have not been loaded
  • ReloadScripts()
    Invokes the handler's _reloadall() function (no arguments) which reloads all loaded scripts
  • ReloadScript( string scriptName )
    Invokes the handler's _reload( string scriptName ) function which reloads the specified script
  • Protocol commands:
  • SendProtocol( string data )
    Send a single line of protocol to the server; newline will be appended before sending
  • HandleProtocol( string data )
    Handle a single line as if it were received from the server, no newline required
  • Lobby control commands:
  • Disconnect()
    Closes the socket
  • ExitLobby()
    Closes the lobby
  • Unitsync control commands:
  • User data commands:
more to come later
Last edited by aegis on 09 Jul 2008, 02:40, edited 1 time in total.
Post Reply

Return to “Engine”