Skip to content

Commit

Permalink
Update to 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
twisterghost committed Jun 25, 2017
1 parent 70175cc commit 8a31bba
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Patchwire for GameMaker: Studio
GameMaker client scripts for the Patchwire multiplayer server framework

Version 1.0.0
Version 1.1.0

Compatible with [Patchwire 0.2.*](https://github.com/twisterghost/patchwire).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ if (ds_map_exists(global.patchwire_netHandlerMap, argument0)) {
handlerList[0] = argument1;
ds_map_add(global.patchwire_netHandlerMap, argument0, handlerList);
}

1 change: 1 addition & 0 deletions patchwire-gm/scripts/net_cmd_init/net_cmd_init.gml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
global.patchwire_netCurrentData = ds_map_create();
ds_map_add(global.patchwire_netCurrentData, "command", argument0);
return global.patchwire_netCurrentData;

35 changes: 22 additions & 13 deletions patchwire-gm/scripts/net_cmd_parse/net_cmd_parse.gml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@

var netResponseType = ds_map_find_value(async_load, "type");

if (netResponseType == network_type_data) {
var netResponseBuffer = ds_map_find_value(async_load, "buffer");
var netResponseData = buffer_read(netResponseBuffer, buffer_string);
buffer_seek(netResponseBuffer, buffer_seek_start, 0);
var netResponseMap = json_decode(netResponseData);
buffer_delete(netResponseBuffer);
return netResponseMap;
} else if (netResponseType == network_type_connect) {
return -2;
} else if (netResponseType == network_type_disconnect) {
return -3;
} else {
return -1;
switch (netResponseType) {
case network_type_data:
var netResponseBuffer = ds_map_find_value(async_load, "buffer");
var netResponseData = buffer_read(netResponseBuffer, buffer_string);
buffer_seek(netResponseBuffer, buffer_seek_start, 0);
var netResponseMap = json_decode(netResponseData);
buffer_delete(netResponseBuffer);
return netResponseMap;
case network_type_connect:
case network_type_non_blocking_connect:
global.patchwire_connectedStatus = async_load[? "succeeded"];

if (async_load[? "succeeded"]) {
return NetEvent.Connect;
}
return NetEvent.ConnectFail;
case network_type_disconnect:
global.patchwire_connectedStatus = false;
return NetEvent.Disconnect;
default:
return NetEvent.Unknown;
}

12 changes: 11 additions & 1 deletion patchwire-gm/scripts/net_cmd_resolve/net_cmd_resolve.gml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ if (netResponse >= 0) {
var command = ds_map_find_value(netResponse, "command");
net_handle_command(command, netResponse);
}

if (ds_exists(netResponse, ds_type_map)) {
ds_map_destroy(netResponse);
}

} else {
if (netResponse == NetEvent.ConnectFail) {
net_handle_command("connectFailed", "");
} else if (netResponse == NetEvent.Disconnect) {
net_handle_command("disconneded", "");
}
}

ds_map_destroy(netResponse)

1 change: 1 addition & 0 deletions patchwire-gm/scripts/net_cmd_send/net_cmd_send.gml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ buffer_delete(buffer);
if (argument_count <= 1 || !argument[1]) {
ds_map_destroy(dataMap);
}

10 changes: 7 additions & 3 deletions patchwire-gm/scripts/net_connect/net_connect.gml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/// @desc Connects to a server via a socket.
/// @param {String} ServerIP
/// @param {Real} ServerPort
/// @param {String} ServerIP An IP to connect to as a string. e.g. "127.0.0.1"
/// @param {Real} ServerPort A port as a number to connect on. e.g. 3000

network_connect_raw(global.patchwire_netSock, argument0, argument1);
var res = network_connect_raw(global.patchwire_netSock, argument0, argument1);

if (res < 0) {
net_handle_command("connectFailed", "");
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ if (ds_map_exists(global.patchwire_netHandlerMap, argument0)) {
script_execute(handler, argument1);
}
}

30 changes: 29 additions & 1 deletion patchwire-gm/scripts/net_init/net_init.gml
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
/// @desc Initializes the net system.
/// @param {Real} optionalTimeout a connection timeout in milliseconds. Default: 4000
/// @param {Boolean} optionalBlocking `true` to pause while connecting, false otherwise. Default: true

var timeout = 4000;
var blocking = 0;

if (argument_count > 0) {
timeout = argument[0];
}

if (argument_count > 1) {
if (argument[1]) {
blocking = 0;
} else {
blocking = 1;
}
}

network_set_config(network_config_connect_timeout, timeout);
network_set_config(network_config_use_non_blocking_socket, blocking);
global.patchwire_netSock = network_create_socket(network_socket_tcp);
global.patchwire_netHandlerMap = ds_map_create();
global.patchwire_netHandlerMap = ds_map_create();
global.patchwire_connectedStatus = false;

enum NetEvent {
Command = 0,
Connect = -1,
Disconnect = -2,
ConnectFail = -3,
Unknown = -4
}

0 comments on commit 8a31bba

Please sign in to comment.