Giter Site home page Giter Site logo

evolutionleo / warp Goto Github PK

View Code? Open in Web Editor NEW
119.0 7.0 5.0 18.18 MB

Warp is a feature-rich framework for multiplayer games, written in GameMaker and NodeJS (previously GM-Online-Framework)

License: MIT License

Game Maker Language 22.26% JavaScript 37.98% TypeScript 38.42% HTML 0.15% Batchfile 1.20%
tcp-server tcp-client nodejs gms2 gamemaker multiplayer online typescript javascript framework

warp's Introduction

Warp (previously GM-Online-Framework)

A feature-rich framework for multiplayer games, written in GameMaker and Node.js

Maintained by @evolutionleo

If you have any questions, please join my Discord

Features

  • Simple API to send/process packages on both server and client sides with a single line of code
  • No need to deal with buffers whatsoever
  • Advanced systems: server-side physics, entities, lobbies, account/profile system, saving/loading data with MongoDB
  • Well-commented source code for better readability
  • NodeJS server can run on a Linux hosting/dedicated server, as opposed to servers in GML
  • MIT license (you can use Warp in commercial projects and contribute/modify it in any way)

Examples (use old versions)

Installing

Client + Server (recommended)

  • You need to have NodeJS and npm installed
  • Install the package with npm i -g @evoleo/create-warp-app
  • Run npx create-warp-app
  • Select the client and server templates
  • Done! The script will automatically bootstrap a new project from the latest release

Client and Server separately

Client-side

  • Install .yymps from the latest release
  • Import it to your project using GameMaker's Local Package system (you can also choose to include the Demo) OR
  • Install GMClient.zip and unzip it

Server-side

  • Install NodeJS (along with npm)

  • Install VS Code (or use any other code editor of your choice)

  • (TypeScript) Install the Typescript compiler with npm i -g typescript

  • Download JSServer.zip or TSServer.zip from the latest release

  • Open the clonned folder in the command line (or open the folder in VS Code)

  • Run npm install

  • (Optional) To use the accounts/saving system, install the database engine:

Database (Optional)

  • Install MongoDB
  • Choose the default settings, it should now run in the background
  • Done!

If you don't need MongoDB - please disable it in the server's config file (it's under common_config.db_enabled), otherwise you will get an error!

Usage/Workflow

Congratulations on completing the Installation step!

Starting with netcode might be a bit overwhelming at first (even to experienced devs), which is why I tried to make implementing basic client/server interaction as simple and straightforward as possible:

Sending a packet (JS/TS and GML)

Sending a message to the server might be as easy as:

send({ cmd: "hello", str: "Hello, Server!" })

or even (if you create a wrapper function):

sendHello()

Receiving a packet

GML:

addHandler("hello", function(data) {
    show_debug_message(data.str)
})

JS/TS:

addHandler("hello", (client, data) => {
    console.log(`${client.name} says: ${data.str}`)
})

Using lobbies and maps:

  • Add new maps in the maps/ folder
  • Choose how many lobbies you want to create initially in initializers/04_lobbies.js
  • Use the commands "lobby list", "lobby join", "lobby leave" to work with lobbies
  • Configure lobbies' behaviour inside the server's config file (under config.lobby)
  • If you need any specific features for your game that aren't supported by existing configs,
  • You can extend/change the Lobby class in concepts/lobby.js and the Map class in concepts/map.js

Using entities and rooms:

  • (You can always disable entities and rooms completely from config.js if you don't need the functionality for your game)
  • Entity types are located inside entities/entity_types/, you can add new ones or modify/delete the existing ones
  • Your custom entities generally should inherit from PhysicsEntity if they are moving and colliding with other entities, and from the regular Entity class otherwise
  • You only need to code the entities behaviour logic once, on the server-side. The client will then interpolate between the data that it receives
  • The Entity.create() and Entity.update(dt) methods function similarly to GameMaker's Create and Step events (except tps (the game's tickrate) is 20 by default as opposed to 60 in GM, and so it's recommended to use the dt (aka "delta time") parameter to implement your game physics in a tickrate-agnostic way)
  • The Entity.object_type property links the server-side entities to GameMaker's instances/objects
  • Rooms are automatically loaded with all the entities from GameMaker's .yy files from a path defined in config.js (by default it's a path to the Client/rooms/ folder)

Using accounts and saving:

  • Make sure you installed MongoDB (instructions in the Installing section)
  • Use the "register" and "login" commands on the client-side, the server will do all the authentification for you
  • Info: "Account" is an object that holds a pair of login + password, and some data bound to them, while "Profile" is intended to hold the actual gameplay data. One Account could theoretically have many Profiles bound to it
  • You can access the gameplay data of each client in c.profile.%some_variable%, it will save automatically
  • If you want to add new properties, extend the schemas in the schemas/ folder

Running

  • Client runs as a normal GMS2 project
  • (TypeScript) Compile the server by running npx tsc (or npx tsc -w to avoid recompiling after every change)
  • To start the server, navigate to its folder and run node . or npm run dev in the command line

Configuration

  • Edit the server configs inside config.js
  • Edit the client configs inside __NetworkingConfig.gml
  • Select the server config by appending --env=prod or --env=dev parameter to the node . command
  • Select the client config by clicking the 'target' button in the top-right corner of IDE

Deploying

  • Install Node.js and npm
  • Install and configure MongoDB if you're using it in your project
  • Copy the JS/TS Server folder over, along with the rooms/ folder from the GameMaker's project
  • Navigate to the folder in command line
  • Install all the necessary packages using npm install
  • Run npm run prod or node . --env=prod
  • (Optional) Use a tool like PM2 for running the server in the background and managing the process
  • Don't forget to change the client's config to "Prod" by clicking the target button in the top right corner of the IDE!

Contributing

Rules for submitting a PR:

  • Please try to keep the coding style consistent with the rest of the project (e.x. use tabs instead of spaces, etc.)
  • When modifying the server code - please only edit the TypeScript version, as it can be then automatically translated to JS, but not the other way around
  • After you've made your changes to the TS server, go to /autorelease/ and run npm run release to compile everything to JS and create the .zip files in /Release/
  • I only accept pull requests with new features that in my opinion make sense for the framework, so if you want to introduce a brand new feature, please lmk first (create a new issue or ask on Discord) because it could be either something that I don't want to be a part of Warp, or it already has an alternative, or it's just something that I'd want to implement myself

Feature requests/typos/bug reports:

  • Check if someone has already made an issue about your bug/feature on the issues tab
  • If not, open a new issue detailing the bug that you found in Warp/the feature that you want to be implemented
  • If it's a feature request, please write why it makes sense to include it/what problem it solves

Credits

warp's People

Contributors

davawen avatar dependabot[bot] avatar evolutionleo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

warp's Issues

Spelling Issue #2

export function entityExists(entiyType: typeof Entity|string): boolean {

export function entityExists(entiyType) {

Found another one, should be "entityType".

Edit:

let regex = /\,(?=\s*?[\}\]])/g; // remove trailing commans

let regex = /\,(?=\s*?[\}\]])/g; // remove trailing commans

Should be "commas".

Change the name of Warp

Really impressed by this library, the best multiplayer solution out there. Took me ages to find.
The project's name needs to represent its purpose. Imo the previous project name did this better. Also, Warp is difficult to find because of game maker's travel off-screen warp function.

Also, a brief overview in the GitHub Readme Page/Wiki of how the server specifically works (Or is designed) would really help people pick the project up.

Broadcast functions do not exclude current client

First of all, thank you for creating this framework! Buffers are just not friends of mine...

However it looks like "notme" flag in broadcastList function doesn't work as intended as "this" is always undefined in the context of the comparison function.

Easy fix:

    broadcastList(clients, pack, notme = true) {
        let me = this;
        clients.forEach(function (client) {
            if (client === me && notme) {
                // skip me
            } else {
                client.write(pack);
            }
        });
    }

Cheers!

node parsing failed

gms sned:Encoding data: { x : 766, y : 261, cmd : 8, mid : "ujQnPFJP1wa" }
node parsing failed:
\node_modules@msgpack\msgpack\dist\Decoder.js:85
throw this.createExtraByteError(this.pos);
^

RangeError: Extra 16 of 30 byte(s) found at buffer[14]
at Decoder.createExtraByteError (D:\typescript\js_server - 副本 (2)\node_modules@msgpack\msgpack\dist\Decoder.js:78:16)
at Decoder.decode (D:\typescript\js_server \node_modules@msgpack\msgpack\dist\Decoder.js:85:24)
at decode (D:\typescript\js_server \node_modules@msgpack\msgpack\dist\decode.js:13:20)
at Function.parse (D:\typescript\js_server\packet.js:25:20)
at Socket. (D:\typescript\js_server\main.js:43:25)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

Uncaught TypeError: crypto.randomInt is not a function

Debugger attached.
Waiting for the debugger to disconnect...
c:-redacted-\Server\internal\lobbyFunctions.js:9
var lobbyid = crypto.randomInt(100000, 999999).toString();
^

TypeError: crypto.randomInt is not a function
at module.exports.createLobby (c:-redacted\Server\internal\lobbyFunctions.js:9:30)
at c:-redacted-\Server\internal\initializers\03_lobbies.js:5:5
at Array.forEach ()
at Object. (c:-redacted-\Server\internal\initializers\03_lobbies.js:4:13)
at Module._compile (internal/modules/cjs/loader.js:971:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
at Module.load (internal/modules/cjs/loader.js:822:32)
at Function.Module._load (internal/modules/cjs/loader.js:730:14)
at Module.require (internal/modules/cjs/loader.js:864:19)
at require (internal/modules/cjs/helpers.js:74:18)
at c:-redacted-\Server\server.js:15:5
at Array.forEach ()
at Object. (c:-redacted-\Server\server.js:14:12)
at Module._compile (internal/modules/cjs/loader.js:971:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
at Module.load (internal/modules/cjs/loader.js:822:32)
Process exited with code 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.