{"id":13530491,"url":"https://github.com/gm-core/patchwire-gm","last_synced_at":"2025-04-01T18:31:51.961Z","repository":{"id":86405463,"uuid":"41973649","full_name":"gm-core/patchwire-gm","owner":"gm-core","description":"Simplified networking for GameMaker: Studio 2 using the Patchwire multiplayer server framework","archived":false,"fork":false,"pushed_at":"2020-09-13T15:00:16.000Z","size":46,"stargazers_count":32,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-02T17:36:15.366Z","etag":null,"topics":["gamemaker","multiplayer","networking","patchwire"],"latest_commit_sha":null,"homepage":"https://gmcore.io/patchwire/","language":"Yacc","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gm-core.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-09-05T19:52:49.000Z","updated_at":"2024-03-27T15:44:14.000Z","dependencies_parsed_at":"2024-01-03T04:08:03.635Z","dependency_job_id":"472ea326-90f1-4b6b-a34b-e859dbd01a0f","html_url":"https://github.com/gm-core/patchwire-gm","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gm-core%2Fpatchwire-gm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gm-core%2Fpatchwire-gm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gm-core%2Fpatchwire-gm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gm-core%2Fpatchwire-gm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gm-core","download_url":"https://codeload.github.com/gm-core/patchwire-gm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246691618,"owners_count":20818542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gamemaker","multiplayer","networking","patchwire"],"created_at":"2024-08-01T07:00:50.715Z","updated_at":"2025-04-01T18:31:51.717Z","avatar_url":"https://github.com/gm-core.png","language":"Yacc","readme":"# Patchwire for GameMaker: Studio\nGameMaker client scripts for the Patchwire multiplayer server framework\n\nVersion 2.0.0\n\nCompatible with [Patchwire 0.5.*](https://github.com/twisterghost/patchwire).\n\n## Installation\n\nDownload the latest .yymps [release](https://github.com/gm-core/patchwire-gm/releases) of Patchwire and import the local package. For detailed instructions, see [this guide](https://gmcore.io/installing.html)\n\n## Usage\n\nPatchwire is great for simple online connectivity and centers around a paradigm of sending \"commands\" to and from a server. A command has a name and data associated with it. For example, consider a command called \"chat\" which has two pieces of data: the user that send the message, and the message.\n\nYour game would send a \"chat\" command to the [server](https://github.com/twisterghost/patchwire), which would see the command and handle it. Likely, the server would just broadcast the same command back to all other connected clients. Those clients would then have their own \"chat\" command handler.\n\nAs such, most of the Patchwire API centers around creating, sending and receiving \"commands\". You will establish \"command handlers\" to handle incoming commands from the server, and you will send commands back out.\n\n#### Creating a network manager object\n\n```GML\n// obj_network_manager - Create\nnet_init();\nnet_connect(\"YOUR_SERVER_IP\", YOUR_SERVER_PORT);\n```\n\nThis will initialize the client networking and connect to the given Patchwire server. Upon connecting, the client will receive a `connected` command. Let's go over how commands are handled next.\n\n```GML\n// obj_network_manager - Create\n\nnet_cmd_add_handler(\"connected\", function(data) {\n  status = \"Connected\";\n  name = data[? \"name\"];\n});\n```\n\n```GML\n// obj_network_manager - Networking\nnet_resolve();\n```\n\nIn the create event, we specify a handler function for the `connected` command. In the networking event, we tell the Patchwire client to handle incoming commands with `net_resolve()`. In this case, when the `connected` command is received, its contents will be sent to the provided function, which can do whatever you please. In this case, we're just setting some variables. The first parameter of the handler function will be a ds_map of data from the server. This map will be automatically destroyed after all handlers run.\n\n#### Writing command handler scripts\n\nLets use the example of writing a handler for a `chat` command from the server. We have connected to the server and added a command handler for the `chat` command to use `handle_chat` to handle the command. Let's say the server sends us a chat command that looks like this:\n\n```JavaScript\n{\n    command: 'chat',\n    user: 'twisterghost',\n    message: 'Hello, world!'\n}\n```\n\nPatchwire will route this command into the handler, providing the command JSON as a `ds_map`, so we can handle it like this:\n\n```GML\nnet_cmd_add_handler(\"chat\", function(data) {\n  show_message(data[? \"user\"] + ': ' + data[? \"message\"]);\n});\n\n```\n\nAgain, you do not need to handle deleting the data map after your handler script runs. Patchwire cleans it up for you.\n\n#### Sending commands to the server\n\nSending a command is just as important as handling one, but much easier! To send a command, use the following syntax:\n\n```GML\n// Initialize the command, returns a ds_map\nvar command = net_cmd_init(\"SOME_COMMAND_TYPE_HERE\");\n\n// Optionally add data to the command\ncommand[? \"someKey\"] = \"someValue\";\n\n// Send the command to the server\nnet_cmd_send(command);\n```\n\n\u003e **NOTE:** If you don't provide the `command` value in `net_cmd_init`, Patchwire will just send whatever the most recently created command was.\n\n# Docs\n\nFor more documentation, see:\n\n* [Patchwire-GM Wiki](https://github.com/twisterghost/patchwire-gm/wiki)\n* [Patchwire](https://github.com/twisterghost/patchwire)\n\n## GM Core\n\nPatchwire-GM is a part of the [GM Core](https://github.com/gm-core) project.\n","funding_links":[],"categories":["Networking"],"sub_categories":["Recommendations"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgm-core%2Fpatchwire-gm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgm-core%2Fpatchwire-gm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgm-core%2Fpatchwire-gm/lists"}