-
Notifications
You must be signed in to change notification settings - Fork 8
Remote admin
Servers can be controlled remotely from a JavaScript client (if you enable this functionality by starting your server with the "-admin" option). There is some basic built-in commands and you can create your own too. This whole interface is protected by a password that you need to enter on every socket connections to be granted with admin privileges.
Note: the remote admin functionnality is not present in the Basic_SocketServer class, you need to use the full featured SocketServer class.
##List of built-in commands To send these commands to the server, use the "sys_send" method of the SocketClient.
- login
- Enable you to login as admin if you send the good password. This step is required to use all others commands bellow.
- logout
- Revoke your admin privileges.
- kick
- Disconnect a client by passing it's ID.
- shutdown
- Shutdown the server.
- sleep
- Put the server into sleep for X seconds.
- clients_count
- Send back the count of connected clients on the server.
- clients_list
- Send back the list of all connected clients on the server with some infos such as their ID and there privileges level (user or admin).
- ping_client
- Enable you to receive the ping of a specific client by passing it's ID.
- last_error
- Send back the last PHP error encountered by the script (if any).
- options
- Send back the list of options passed to the server when it started.
It's pretty easy, just declare a method called "sys_handle_[NAME_OF_YOUR_COMMAND_HERE]" on your server and it'll be executed when a client is trying to execute it the same way as built-in commands.
Note: Don't create commands with the same name as built-in commands or they won't be executed.
Next step is telling the server that this new command require admin privileges (because yes, you can create custom commands that dosen't require admin access), just use the "register_admin_command" method in your init method by passing your command name as a string or an array of command names. That's it ! :)