theCapypara / GMnet-ENGINE

A multiplayer/networking engine for Game Maker Studio
https://gmnet-engine.org/
Other
77 stars 21 forks source link

Error trying to separate client from server #53

Closed Madirex closed 7 years ago

Madirex commented 7 years ago

I am trying to create a server and a separate client, that the clients will all connect to the server and the server will process all the information. But I have not succeeded because It appears to me this error:

############################################################################################
ERROR in
action number 1
of Async Event: Networking
for object obj_htme:

Creating instance for non-existing object: 35
 at gml_Script_htme_recieveVarGroup (line 77) -         instance = instance_create(-100,-100,object_id);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_htme_recieveVarGroup (line 77)
called from - gml_Script_htme_serverNetworking (line 37) -             htme_recieveVarGroup();
called from - gml_Script_htme_networking (line 38) -         htme_serverNetworking();
called from - gml_Object_obj_htme_NetworkingEvent_1 (line 2) - htme_networking();

I created a step event on different object

var port = real(get_string("Port: ","4000"))

if(htme_serverStart(port,4000)){
room_goto(servidor);
} else {
show_message("Error al iniciar el servidor.")
game_end();
}

and other object named htme_obj_netcontrol Step:

if(!htme_isStarted()) {
show_message("Error reiniciando...");
game_restart();
}

I do not know what is wrong, I start the server and when I start the client and try to connect to the server, the server skips that message

I tried to put the client and the server all together and there does not jump any type of error, but I want to do it separately

theCapypara commented 7 years ago

Your server has to have all the objects that the clients have. They also have to have the same ID (the ID is generated by GameMaker).

It seems that your server (or client) game misses an object.

Example:

If you want to seperate client and server logic, make sure your server and clients have the same objects. I am not sure if there is a way in GameMaker to control the ids of objects, but you also have to make sure objects with the same name on the server and client have the same ids.

Madirex commented 7 years ago

The problem is that I am trying to make a game with the server and the different client, and my idea is that the server collects the information of the users, and that the clients are the players, and the server is only to handle the information and Send it to the players, I do not want the server can also play, I want the server can only handle it for the players to connect (like an MMORPG)

Then anyone could knock down my server if it tries to login and the object does not exist

theCapypara commented 7 years ago

Hm, I see.

To use GMnet in such a way, you can not use instance syncing (via the mp_* commands). Instead you'd need to use the lower level networking commands, such as the CHAT API (https://gmnet-engine.org/manual/engine/concepts/chat) which also supports executing commands via RPC (http://manual.gmnet-engine.org/en/version2/engine/tutorial/17_rpc.html).

If you want to use instance syncing, GMnet had to be extended in a way that allows custom object mapping.

I would agree though that the server should not crash when getting an invalid object. This is definitely an issue.

I don't maintain this project actively anymore and I'm depended on community input. I can provide you with support for fixing it yourself though:

https://github.com/Parakoopa/GMnet-ENGINE/blob/4b206199e3458c77eda0b1f049371d280316ae97/GMnetENGINE.gmx/scripts/htme_recieveVarGroup.gml#L93 Here the server/client tries to create the object. You could add a simple Game Maker function to check if an object with the id object_id exists and if not gracefully disconnect from the server / client. This would at least fix the security issue.

EDIT: I just noticed that a method of creating objects not via ID but via their actual name already exists (I think The Any Key added it). You can activate the option in the configuration: https://github.com/Parakoopa/GMnet-ENGINE/blob/4b206199e3458c77eda0b1f049371d280316ae97/GMnetENGINE.gmx/scripts/htme_config.gml#L32

Combined with the above security fix you should be able to get your game running. Please note hat the names of the objects still have to be the same even with this configuration option.

If you need any more support, don't be afraid to ask :)

The-any-Key commented 7 years ago

The main problem is that when having two different projects your objects id will vary. Ex obj_htme will have the id 100123 in the server and 100432 in the client project. In the new version you can set the htme_config to self.use_string_asid=true; This will make GMnet use object string names instead of id. So the server and client project can have a different amount of objects in the project. This will allow you to separate the server from the client. But you will need the objects that you sync on the server because GMet need to temporary create them on the server to gather the needed mp settings. Else the server won't know what the object is syncing. You can simply check if the object is a temp object with the new htme_isTemp() and skip code in the object that you don't want to run on the server.