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:
- The Web Server sends a signed command (HMAC-SHA256, time-limited, single use) to the
START.exegate. - 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.
- GameServer calls the function
WebAPI.<name>(aIndex, params)inData\Plugin\WebAPI\WebAPI.lua. - 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.inisection[Plugin]hasTSWMUWeb = 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 = 1in[Plugin](and LuaApi purchased):WebAPI.luais loaded into the same Lua engine asMain.lua.Enable = 1inData\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.
| Key | Value | Default | Meaning |
|---|---|---|---|
url_server | web URL | empty | Address of your Web Server (admin site). The IP of this address is automatically allowed to connect. |
Enable | 0 / 1 | 0 | 1 = open the gate; 0 = closed. |
ListenIP | IP | 127.0.0.1 | 127.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). |
Port | TCP port | 44470 | Port of the START gate. Open the firewall only for the Web Server machine. |
Key | string, at least 32 characters | empty (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. |
AllowIP | list of IPs, separated by commas | 127.0.0.1 | Additional IPs allowed to connect (127.0.0.1 is always allowed). |
TimeWindow | seconds, 10..600 | 60 | Maximum clock difference between the Web Server and this machine. |
Timeout | ms, 1000..30000 | 8000 | Time to wait for GameServer to reply. |
MaxPerMinute | 10..100000 | 600 | Maximum number of commands per minute from one IP. |
Log | 0 / 1 | 1 | 1 = 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
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...).
paramsis a table of strings sent by the web (usetonumber); 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 returnsfalse.- A function returns
ok(true/false),message(text shown to the player on the web), and an optionaldatatable (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
| Function | params | Purpose |
|---|---|---|
info | - | Returns live character data: name, level, master, majestic, reset, points, Zen, PK, map, coordinates, 5 stats, WCoin, Goblin Point, Ruud. |
reset | min_level, min_master, max_resets (0 = unlimited), points (reward), keep_stats (1 = keep stats), base_str/agi/vit/ene/cmd | Resets 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. |
resetstats | min_level, base_* | Returns stats to the class starting values; the difference becomes free points. |
addstats | min_level, minimum, maximum, str/agi/vit/ene/cmd | Adds stat points from free points. |
clearpk | - | Clears PK (back to normal). Rejected if the character is not a murderer. |
unstick | map, x, y | Teleports the character to a safe place. |
clearmaster | min_level, min_master | Resets the master skill tree (refunds points). |
zen_add / zen_take | zen | Adds / subtracts Zen (withdraw from / deposit to the web bank). The character must not be busy (trading, shop, teleporting). Maximum 2,000,000,000 Zen. |
gremory | index, 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_set | level, master_level, points, master_points, money, reset, map, x, y | Admin edits an online character. Only changes keys that are sent and differ from the current value. |
jewel_take | codes (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). |
items | box (1 = inventory, 2 = warehouse) | Lists the items in the inventory or warehouse as records. |
item_take | box, slot, serial | Takes 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_give | record | Returns 1 item from the web chest to the Gremory case (Personal Store tab). |
buff | item, seconds | Activates a Cash Shop charm / scroll (kept after logging in again). |
coin | wcoin, goblin (positive = add, negative = subtract) | WCoin / Goblin Point when the account is online. |
ruud | amount (positive = add, negative = subtract) | The character's Ruud (web market). |
notice | text | Sends 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
- Open
Data\Plugin\WebAPI\WebAPI.lua. - Add a function of the form
function WebAPI.function_name(aIndex, params) ... return true, "", { ... } end. - 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
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 changeTSWMUWeborLuaApiinPlugin.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".