Network Controller
The network controller is the interface between awesomenet and your game. Every AwesomeNet functionality you want to use in your game needs to be implemented by using the network controller. This documentation lists all functions of the network controller and briefly describes them. Please note, that you don't need to go this deep if you don't want extended functionallity. See Matchmaking Functionallity and Network Gameobjects if you haven't implemented the basic network functionallity of your game yet!
Unity Setup
All networking features are managed by the network controller. This script needs to be present in a gameobject tagged "NetworkController" in the scene in which you connect to matchmaking and from which game scenes are loaded. Most of the time this is the intro/menu scene. There is no need in adding the network controller to any other scene as it will not be destroyed if another scene is loaded. It will be and needs to be active on every scene. A prefab of the preconfigured network controller game object is located in the "Prefabs" folder of the Asset Store Packgage.
The gameobject needs to be tagged "NetworkController" for the gameobjects containing a network gameobject connector to find the network controller in order to send network commands.
Matchmaking functionallity
ConnectMatchmaking ( string host, int port )
public bool; returns: true
on success; false
on error or if allready connected
argument | description |
---|---|
host | ip or hostname (string) |
port | port (int) |
Connects the game client to a AwesomeNet matchmaking server.
DisconnectMatchmaking ( )
public bool; returns: true
on success; false
on error or if not connected
Disconnects a game client from a AwesomeNet matchmaking server
JoinGame ( string id, string player )
public bool; returns: true
on success; false
on error or if not connected
argument | description |
---|---|
id | game uinque id (string) |
player | player name (string) |
Joins the client into a game specified by the games unique id. To get a list of all advertised games with unique ids see GetGameList()
If successfull you should load the game scene after this. This function needs an active matchmaking server connected to work!
GetGameList ( )
public string[]; returns: { "number_of_games"; "game_id; host_playername; map_name"... }
on success; false
on error or if not connected
Returns a string array containing information about currently advertised games. The first field of the array contains the number of games and every following field contains information about a game seperated by semicolons. The first section consists of the game unique id, the following contains the name of the player that created the advertisement and the third section contains the name of the match the game takes place on. See Matchmaking Functionallity for an example to parse these infromation into a usable format. This function needs an active matchmaking server connected to work!
NewGameOnline ( string map, string player )
public bool; returns: true
on success; false
on error or if not connected
argument | description |
---|---|
map | map name (string) |
player | player name (string) |
Advertises a new game on a specific map and automatically joins the client into the newly created game. If successfull you should load the game scene after this. This function needs an active matchmaking server connected to work!
NewGameOffline ( string map, string player )
public bool; returns: true
.
argument | description |
---|---|
map | map name (string) |
player | player name (string) |
Creates a local game session for one player on a specific map. You should load the game scene after this. This function needs no active matchmaking server connected.
GetGameInfo ( string id )
public GameInfo; returns: GameInfo struct containing information about the game with the id specified
on success; Empty GameInfo struct
on error or if not connected
Returns a struct of the type GameInfo. GameInfo has three fields containing the following information about a game:
field | description |
---|---|
GameInfo.host | name of the player hosting the game (string) |
GameInfo.playercount | currently connected players (int) |
GameInfo.players | array containing the names of the currently connected players (string[]) |
GameInfo.map | name of the map (string) |
This function needs an active matchmaking server connected to work! This for example can be used to implement a player limit for certain maps starting the game automatically if enough players are connected.
GetCurrentGameInfo ( )
public GameInfo; returns: GameInfo struct containing information about the currently running game
on success; Empty GameInfo struct
on error or if not connected or no active online game
Like GetGameInfo
but for the currently running game. This function needs an active matchmaking server connected and a active running online game to work!
Game server functionallity
SendGSCommand ( string objectID, string actionID, object[] argument)
public void
argument | description |
---|---|
objectID | object id (string) |
actionID | action id (string) |
argument | object array containing all arguments. pass empty object array if none (object[]) |
This function executes a function with a specivide actionID on an specified objectID on all connected clients. In nearly any case it is recommended not to use this function and execute a certain function by it's human readable ID via the Network gameobject connector like described in Network Gameobjects