Overview

The TSWMUWeb plugin lets the website (your Web Server) operate directly on characters that are online: reset, add points, add/subtract Zen, WCoin, Goblin Point, Ruud, send items to the Gremory case, take items from the inventory/warehouse into the "web chest", send notices... While a character is playing, the data in the database is not the real data (the server holds it in memory), so the web must ask GameServer to make the change. Players do not see any separate interface in the game; they only see the results and green notices of the form [Web] ....

The path of a command:

  1. The Web Server sends a signed command (HMAC-SHA256, time-limited, single use) to the START.exe gate.
  2. START checks the Key, signature, IP and rate limit, then forwards it to the GameServer that holds that character. If a GameServer does not have the character it replies "not here" so START asks another GameServer.
  3. GameServer calls the function WebAPI.<name>(aIndex, params) in Data\Plugin\WebAPI\WebAPI.lua.
  4. The result (success/failure, message, returned data) is re-signed by START and sent back to the web, so a fake website cannot impersonate it.

Operating conditions

  • The TSWMUWeb plugin is purchased and in Data\Plugin\Plugin.ini section [Plugin] has TSWMUWeb = 1. START checks this condition at the gate and GameServer checks it again. If the condition is not met, GameServer returns the error "TSWMUWeb is not enabled".
  • LuaApi = 1 in [Plugin] (and LuaApi purchased): WebAPI.lua is loaded into the same Lua engine as Main.lua.
  • Enable = 1 in Data\Plugin\WebAPI\config.ini (the START gate).
  • The TSWMU website is installed and declared with the same Key (the Game API admin section of the web).
  • No separate client file is needed.

File Data\Plugin\WebAPI\config.ini (START gate)

START reads this file; changes take effect after about 2 seconds, with no restart needed. A sample file is created by START the first time with the gate off and a random Key. All keys are in the [WebAPI] section.

KeyValueDefaultMeaning
url_serverweb URLemptyAddress of your Web Server (admin site). The IP of this address is automatically allowed to connect.
Enable0 / 101 = open the gate; 0 = closed.
ListenIPIP127.0.0.1127.0.0.1 = this machine only (Web Server on the same machine); 0.0.0.0 = all network cards (Web Server on another machine, the IP must be added to AllowIP).
PortTCP port44470Port of the START gate. Open the firewall only for the Web Server machine.
Keystring, at least 32 charactersempty (the sample file generates one randomly)Secret shared with the Web Server (Game API admin page). Keep it strictly confidential; if the Key is changed, the old Web Server can no longer make calls.
AllowIPlist of IPs, separated by commas127.0.0.1Additional IPs allowed to connect (127.0.0.1 is always allowed).
TimeWindowseconds, 10..60060Maximum clock difference between the Web Server and this machine.
Timeoutms, 1000..300008000Time to wait for GameServer to reply.
MaxPerMinute10..100000600Maximum number of commands per minute from one IP.
Log0 / 111 = write the log START\Log\WebGate_<date>.log.

Example (Key and address hidden):

[WebAPI]
url_server   = http://<web-server-address>:<port>
Enable       = 1
ListenIP     = 0.0.0.0
Port         = 44470
Key          = <secret-string-of-at-least-32-characters>
AllowIP      = 127.0.0.1
TimeWindow   = 60
Timeout      = 8000
MaxPerMinute = 600
Log          = 1
Do not publish or send the content of Key to anyone. Anyone with the Key and an allowed IP can send commands to your characters.

File Data\Plugin\WebAPI\WebAPI.lua (functions the web calls)

The web can only call functions that are in the WebAPI table of this file. Rules:

  • A function not in the table: returns "unknown function: <name>". Names starting with _ are helper functions that the web can never call. Names consist only of letters, digits, _, at most 48 characters.
  • GameServer does not calculate anything for the web by itself; each function checks and changes things using ordinary LuaAPI functions (Player, Item, Coin, Buff, Message...).
  • params is a table of strings sent by the web (use tonumber); at most 64 key=value pairs per command. Prices and rewards come from the web admin page configuration. Fees paid from the web bank are deducted by the web BEFORE the call and refunded if the function returns false.
  • A function returns ok (true/false), message (text shown to the player on the web), and an optional data table (key = value) sent back to the web.
  • Character not online on this GameServer: GameServer replies "not here" so START asks another GameServer. [TO VERIFY: how the website handles the case where no GameServer holds the character (does it use the database?) - this is in the web code, not yet read]

Built-in functions

FunctionparamsPurpose
info-Returns live character data: name, level, master, majestic, reset, points, Zen, PK, map, coordinates, 5 stats, WCoin, Goblin Point, Ruud.
resetmin_level, min_master, max_resets (0 = unlimited), points (reward), keep_stats (1 = keep stats), base_str/agi/vit/ene/cmdResets the character (level back to 1, reset +1, adds reward points). Rejected when ResetServer = 0 in Common.ini, or when the level is insufficient / the reset limit is exceeded.
resetstatsmin_level, base_*Returns stats to the class starting values; the difference becomes free points.
addstatsmin_level, minimum, maximum, str/agi/vit/ene/cmdAdds stat points from free points.
clearpk-Clears PK (back to normal). Rejected if the character is not a murderer.
unstickmap, x, yTeleports the character to a safe place.
clearmastermin_level, min_masterResets the master skill tree (refunds points).
zen_add / zen_takezenAdds / subtracts Zen (withdraw from / deposit to the web bank). The character must not be busy (trading, shop, teleporting). Maximum 2,000,000,000 Zen.
gremoryindex, level, durability, skill, luck, option, exc, ancient, count (1..100), days (0 = 7 days), storage (3 = Personal Store tab by default, 1 = Character tab, 2 = My Server tab)Sends an item to the Gremory case so the player can receive it in the game. Stackable items are merged into full stacks.
admin_setlevel, master_level, points, master_points, money, reset, map, x, yAdmin edits an online character. Only changes keys that are sent and differ from the current value.
jewel_takecodes (list of item codes, separated by commas)Takes jewels from the inventory to deposit into the web bank (inventory slots only, level 0, no expiry).
itemsbox (1 = inventory, 2 = warehouse)Lists the items in the inventory or warehouse as records.
item_takebox, slot, serialTakes 1 item from the inventory / warehouse into the web chest (the item is deleted from the game immediately). Rejected if the character is busy, the warehouse is password-locked, or the item is locked / has an expiry / is Pentagram / Errtel.
item_giverecordReturns 1 item from the web chest to the Gremory case (Personal Store tab).
buffitem, secondsActivates a Cash Shop charm / scroll (kept after logging in again).
coinwcoin, goblin (positive = add, negative = subtract)WCoin / Goblin Point when the account is online.
ruudamount (positive = add, negative = subtract)The character's Ruud (web market).
noticetextSends a green notice (at most 200 characters) to the character.

In-game messages sent by the functions have the prefix [Web] (for example "[Web] Reset N done, +N points", "[Web] Item sent to the Gremory case (Personal Store)"). This text is directly in WebAPI.lua, not in Lang; to change it, edit the Lua file.

Adding or editing a function

  1. Open Data\Plugin\WebAPI\WebAPI.lua.
  2. Add a function of the form function WebAPI.function_name(aIndex, params) ... return true, "", { ... } end.
  3. Save the file and then click Reload plugin.
function WebAPI.notice(aIndex, params)
	_notice(aIndex, tostring(params.text or ""):sub(1, 200))
	return true, ""
end
A new function is only useful if the website also has a feature that calls that function name; the TSWMU website only calls the functions available in the table above. [TO VERIFY: the website owner should confirm the list of functions the website really calls]

Reloading

  • config.ini: reloaded automatically after about 2 seconds when the file changes.
  • WebAPI.lua: click the Reload plugin button on the GameServer control panel (it calls a LuaAPI reload). Also click this button when you change TSWMUWeb or LuaApi in Plugin.ini.

Log and return codes

For each command GameServer writes one line [WebAPI] <function name> -> <character name> (guid ...) = <code> <message>. Common errors returned to the web: "LuaAPI is not loaded", "WebAPI.lua is not loaded", "unknown function: ...", "bad request", "script busy".