Setting up your game for online multiplayer is considered an advanced topic, so it is recommended that you familiarize yourself with 001 Game Creator in general before attempting to implement this.
An online game generally consists of multiple instances of a game running at the same time, where one instance of the game is considered the server whom hosts the game, and the rest of the instances of the game are considered the clients whom connect to the server.
The mechanism used for network communication is TCP/IP using BSD sockets.
The following is an overview of the procedure of how online multiplayer games function in 001 Game Creator:
Two or more instances of the game are run at similar moments in time.
The server, determined by using a “Comparison Branch” event with the “Launched as Server” use value, hosts the game using the “Host Game Server” event.
A client thereafter connects to the server using the “Connect to Game Server” event.
When the server receives a connection, the “Connection Received” system trigger is executed on the server with a parameter variable “ip” containing the IP address of the connecting client and a parameter variable “id” containing a unique number identifying the client (which can be used in other events).
Once the client realizes that it has made the connection, the left branch of the “Connect to Game Server” event continues to execute.
The server and client may freely communicate using Network Messages. That is, the server can execute a network message event causing all clients or a specific client to run the script inside. And vice versa, the client can execute a network message event causing the server to run the script inside.
The server, at any point in time may close the connection using the “Close Connection” event; this can be based on the “ip” value provided by the “Connection Received” system trigger. The client, at any point in time may close the connection in the same way.
During the development process, you should use the IP address “127.0.0.1” for the purposes of hosting and for connecting. This is also called “localhost” and is used to essentially loop-back the connection from one instance of the game to another on the same local machine.
When the game is ready or when you’re wanting to play the game across the network, you should use an empty IP address for hosting on the default Ethernet adapter, or use the IP address of the network adapter desired. Clients should then use the IP address of the server to connect.
The port number you choose should be unique, and likely customizable. Any other software may use any port they choose to use, and if the port is already in use, you may have issues with hosting a server on that same port. It is advisable to choose a port with at least three or four digits in the number.
For a list of registered port numbers and further recommendations, see List of TCP and UDP port numbers on Wikipedia.
Client and Server Roles
During the development of your game, 001 Game Creator offers an option for you to execute multiple instances of the same game by using the “Launch instances for network games” option within the testing options. When the value is 2 or higher, the first instance will be considered the server and the second instance will be considered the client. That is, “Launched as Server” use value will return true for the first instance and false for every other instance. However, if you simply execute the same game multiple times on the same computer once the game is built, each instance will be considered a client unless the game is built as a dedicated server.
Regardless of whether the game is launched as a client or server, any instance may either host a game (become the server) or connect to one (become a client). However, this will not change the “Launched as Server” use value. This allows you to setup a game where any user of your game can either be the server or a client, simply by allowing the user to make that choice. You may use the “Is Hosting” and “Is Connected” use values to determine if indeed hosting a game server or instead connected to one.
Generally, the server makes final calls about whether a client moves to a particular location, damages another player, and so forth. A client generally receives information about the game/map from the server, and sends general commands or intermittent states to the server to delegate to everyone.
Getting a connection established is the most important factor. Always ensure that you’re hosting on the right IP address, connecting to the right IP address, and using a port number that is not already being used by other software on the hosting computer.
It may help to uncheck “Freeze game when game loses focus” in Game Settings, as the game and thus networking functionality won’t proceed unless the particular instance of the game has focus.
When the server receives a connection from a client, it would probably be wise to have the two communicate a bit before throwing everyone into the game. For example, the server can take this opportunity to validate the IP address of the incoming connection, or wait for a secret password from the client to enter a particular game. It all comes down to how the game designer intends to validate a player and what information the server and client need to know about each other.
Most gameplay elements should be transmitted as they happen or change. However, movement is particularly susceptible to noticeable performance issues because of common network issues, such as low latency situations or bandwidth limitations.
A simple solution for handling movement, is to intermittently have the client inform the server of its current location. The server can simply relay this back to the other clients and those clients can merely use a “Walk to Location” event to that new location. It will look just as good as what the other client probably performed, but reduces the amount of data transmitted over the network.
Security and Cheating
Because 001 Game Creator allows you to design how networking actually functions, there is no particular way for it to prevent cheating or hacking. It is the responsibility of the game designer to script things in a way that is most fitting.
In terms of security, it is best to not transmit plain text passwords – consider using hash or encryption algorithms. And in terms of cheating, it is best to validate the network messages that are received from other clients to ensure that the information is reasonable. For example, if a player reports being in one position, but then quickly in another, unrealistic position across the entire map based on a distance calculation, it would be best to trigger some action that would kick the player or report it to a moderator.