Jump to content


Photo
* * * * * 2 votes

C++ Server + Gml Client [Link Fixed]


  • Please log in to reply
26 replies to this topic

#1 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2527 posts
  • Version:GM8

Posted 04 December 2011 - 07:42 PM

  • Title: Nevereal++ Networking Example (39dll C++ server + GML client)
  • Description: Open source Visual Studio 2010 server source and GameMaker 39dll source
  • GM Version: :GM81:
  • Registered: Yes
  • File Type: .zip
  • File Size: ~15MB
  • File Link (fixed 12/13/13): Direct Download Link
  • Required Extensions: None
  • Required DLLs: 39dll

Summary
Develop online games quickly, easily and more efficiently than ever before with the Nevereal++ Networking Engine. This engine was built from scratch both serverside and clientside. The server was coded in Microsoft's Visual Studio 2010 IDE and the client was coded in GameMaker 8.1. The example only has a working login and registration message case coded. It supports MySQL and INIs natively.
In order to edit the server source files, you need to have Microsoft's Visual Studio 2010 C++ Express installed. The IDE can be downloaded free of charge from the Microsoft website here.
In order to use the MySQL, you should have at least server version 5.0 or higher running on your server. The SQL install files can be obtained from the official MySQL website here.

The source is heavily commented so you can quickly pickup the style of the coding. It has diy mini tutorials within the source so that I didn't have to bundle an additional file readme.
Credit is good.

 

NOTE: (12/13/13) If you are trying to compile this with a newer compiler (2012/2013) you will not be able to compile unless you recompile the project dependencies as well.

NOTE: For some odd reason, debug builds of the server crash when using inis. Use only release. I have not been able to find the problem to this

This server runs on MySQL++, SimpleINI and I have bundled HashLib C++. These are all linked to as static libraries (.libs) and I take no credit for them (they belong to their respective authors). I have also compiled and linked across 39dll as a static library, fixing the infamous 39dll reading off of the buffer glitch.

You can also post any questions / problems that you may have on our site's community: http://www.nevereal.net

Spoiler

Edited by 2DLuis, 13 December 2013 - 10:40 PM.

  • 7

#2 Blue2010

Blue2010

    GMC Member

  • New Member
  • 8 posts

Posted 10 December 2011 - 08:02 AM

Well I can't really C++ but I took a brief look at it's source. Unfortunately that seemed like the bulk of the work, because the client had nothing original. Can you tell me some of the beneficial specs to see if I should bother learning C++ for this? For instance, I know that stick online's server was GM made and handled over 100 players relatively well. I tried your 'wuka world2' game in your signature to see any performance perks, but the server must have been down.

This should have more replies though, from users more qualified to critique it than me... What's up guys?
  • 0

#3 CrazyGamer

CrazyGamer

    GMC Member

  • GMC Member
  • 90 posts
  • Version:GM:Studio

Posted 10 December 2011 - 12:40 PM

Could you make a GM 8.0 version of the client? the 8.1 files are not compatible with gm8.0 :|
  • 0

#4 Davidobot

Davidobot

    GMC Member

  • New Member
  • 19 posts
  • Version:GM8

Posted 10 December 2011 - 01:16 PM

Can you make a game maker 8 version plz?
  • 0

#5 mrpeanut188

mrpeanut188

    GMC Member

  • GMC Member
  • 814 posts
  • Version:GM8

Posted 10 December 2011 - 10:22 PM

Could you make a GM 8.0 version of the client? the 8.1 files are not compatible with gm8.0 :|


Can you make a game maker 8 version plz?


Bookmark it.

B.T.W. I wish I knew C++.

Edited by mrpeanut188, 10 December 2011 - 10:28 PM.

  • 1
Posted Image

#6 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2527 posts
  • Version:GM8

Posted 12 December 2011 - 08:58 PM

I would make a GM8 version, but alas I do not have GM8 installed.

Creating a working client in GameMaker 7 or 8 is not terribly hard, just use any networking client really, paying close attention to how 39dll is initialized, the port and buffer password (this is what it looks like in the client.gm81):

Run this in the create event
ip = "127.0.0.1";
port = 1337;
encryption = "bufferpassword";

dllinit(0, true, true);

//Attempt to connect to server on main port
global.server_socket = tcpconnect(ip, port, 1);

//If we couldn't connect
if(global.server_socket <= 0)
{
    show_message("Could not connect on port " + string(port) + ".");
    game_end();
}

Run this in the step event
/*
    Receive all incoming messages and data from the server here. Depending on
    the message that is received, execute an appropriate action in mp_messages()
    
    EXECUTED FROM:
        obj_multiplayer -> Step Event
    
    ARGUMENTS:
        NONE
*/

while(true)
{
    //Constantly receive messages if they're on the buffer
    size = receivemessage(global.server_socket);
    
    //No messaage was on the buffer
    if(size < 0)
    {
        break;
    }
    
    //No connection was detected
    if(size == 0)
    {
        //There was no socket open to listen on...
        show_message("Your connection to the server was lost. The game will now exit.");
        game_end();
        exit;
    }

    //A message was received
    mp_messages();
}

Run this to parse incoming messages:
/*
    Execute the appropriate script(s) based on the unique incoming message
    headers. Add all your multiplayer packet receiving to this file only!
    
    EXECUTED FROM:
        obj_multiplayer -> mp_step()
    
    ARGUMENTS:
        NONE
*/

if(encryption != "")
{
    //Decrypt only if a password was specified
    bufferdecrypt(encryption);
}

message_header = read();

//Execute the appropriate action
switch(message_header)
{
    case MSG_SERVER:
        mp_msg_server();
    break;
    
    case MSG_LOGIN:
        mp_msg_login();
    break;
    
    case MSG_REGISTER:
        mp_msg_register();
    break;
    
    default:
        //Weird message received
        show_debug_message("Unknown message header: " + string(message_header) + ". Data transmission has not completed successfully. Please be aware that some data may have been corrupted in the process.");
    break;
}

Run this to send a message
if(encryption != "")
{
    //Encrypt only if a password was specified
    bufferdecrypt(encryption);
}

//Send message to server
sendmessage(global.server_socket);

CONSTANTS

MSG_LOGIN = 1
MSG_REGISTER = 2
  • 1

#7 jon sploder

jon sploder

    GMC Member

  • GMC Member
  • 919 posts

Posted 16 December 2011 - 12:51 AM

You forgot a setnagle.
  • 0

#8 Debels

Debels

    GMC Member

  • GMC Member
  • 3029 posts
  • Version:GM:Studio

Posted 16 December 2011 - 01:09 AM

Awesome example i was looking for this for 1 week thanks =D

edit: I +1 your post good job =D

Edited by BlueDebel, 16 December 2011 - 01:10 AM.

  • 0

"Give a man a fish, and you feed him for a day; show him how to catch fish, and you feed him for a lifetime."

(Chinese axiom)


#9 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2527 posts
  • Version:GM8

Posted 16 December 2011 - 01:10 AM

Setnagle and other minor improvements will be made in a release scheduled for early next week. In addition, a simple platformer with anti-lag will be included (delaying messages by ping / steps to ensure smooth movement).

Thanks for the positive feedback!

Edited by 2DLuis, 16 December 2011 - 01:11 AM.

  • 0

#10 Debels

Debels

    GMC Member

  • GMC Member
  • 3029 posts
  • Version:GM:Studio

Posted 16 December 2011 - 01:18 AM

Setnagle and other minor improvements will be made in a release scheduled for early next week. In addition, a simple platformer with anti-lag will be included (delaying messages by ping / steps to ensure smooth movement).

Thanks for the positive feedback!


were can i download Microsoft's Visual Studio 2010 IDE?
  • 0

"Give a man a fish, and you feed him for a day; show him how to catch fish, and you feed him for a lifetime."

(Chinese axiom)


#11 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2527 posts
  • Version:GM8

Posted 03 January 2012 - 11:11 PM

were can i download Microsoft's Visual Studio 2010 IDE?



In order to edit the server source files, you need to have Microsoft's Visual Studio 2010 C++ Express installed. The IDE can be downloaded free of charge from the Microsoft website here.


Edited by 2DLuis, 03 January 2012 - 11:12 PM.

  • 0

#12 SeA

SeA

    GMC Member

  • New Member
  • 14 posts
  • Version:GM8

Posted 10 January 2012 - 07:16 PM

nice ...
  • 0

#13 Debels

Debels

    GMC Member

  • GMC Member
  • 3029 posts
  • Version:GM:Studio

Posted 10 January 2012 - 09:29 PM

were can i download Microsoft's Visual Studio 2010 IDE?



In order to edit the server source files, you need to have Microsoft's Visual Studio 2010 C++ Express installed. The IDE can be downloaded free of charge from the Microsoft website here.

I'm installing it atm this is going to be really useful for my online game =D
  • 0

"Give a man a fish, and you feed him for a day; show him how to catch fish, and you feed him for a lifetime."

(Chinese axiom)


#14 EagleWingz7500

EagleWingz7500

    GMC Member

  • GMC Member
  • 15 posts
  • Version:GM8

Posted 09 June 2012 - 04:39 PM

Great examples! Work Very well. Can you explain more C++/server/MySQL ? I need to understand, so i can improve more :D
  • 0
Posted Image

#15 death-droid

death-droid

    GMC Member

  • GMC Member
  • 2600 posts

Posted 20 June 2012 - 03:06 PM

Very good example, though one thing your doing rather wrong as I found out in your mysql handling, with

mysqlpp::StoreQueryResult mysql::execute(string queryString)
{
	mysqlpp::Query ptr = NULL;
	static mysqlpp::StoreQueryResult res;

	try
	{
		if(!mysql::conn->ping())
		{
			//Reconnect
			mysql::connect();
		}

		//Attempt to execute it
		ptr = mysql::conn->query(queryString);
		
		if(res = ptr.store())
		{
			return res;
		}
		else
		{
			server::print(string(ptr.error()), game::c_lightred);
			server::print(string(queryString), game::c_lightred);

			system("PAUSE");
			exit(0);

			return res;
		}
		

		return res;
	}
	catch(const mysqlpp::BadQuery&)
	{
		//Error occured when executing query
		server::print(string(ptr.error()), game::c_lightred);
		server::print(string(queryString), game::c_lightred);

		system("PAUSE");
		exit(0);

		return res;
	}
}

Well more specifically, its this part of the code

		else
		{
			server::print(string(ptr.error()), game::c_lightred);
			server::print(string(queryString), game::c_lightred);

			system("PAUSE");
			exit(0);

			return res;
		}
		


The problem with this is that not all executions return something to be stored, for instance in my case, i used an "INSERT INTO" query. Since theres nothing to actually be stored, your code actually causes the program to stop and exit even when it should not be. If that makes sense (Writing at 1am in the morning)

Edited by death-droid, 21 June 2012 - 05:28 AM.

  • 0

Posted Image


#16 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2527 posts
  • Version:GM8

Posted 03 August 2012 - 03:56 PM

If I'm not mistaken that should return a NULL result object which if you tried to access would crash your program anyways ;)
  • 0

#17 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2527 posts
  • Version:GM8

Posted 15 December 2012 - 04:36 PM

Any suggestions for future updates / bugs?
Keep in mind that I'd like to keep it generic as possible to make it easily adaptable to different online type games.
  • 0

#18 Canuckles

Canuckles

    GMC Member

  • GMC Member
  • 46 posts
  • Version:GM:Studio

Posted 23 December 2012 - 07:23 AM

Any suggestions for future updates / bugs?
Keep in mind that I'd like to keep it generic as possible to make it easily adaptable to different online type games.

Dude, how did I not find this sooner.

Thanks for this my friend!

I will modify my game accordingly and post any suggestions / feedback in the coming weeks :)

Cheers!

Edited by Canuckles, 23 December 2012 - 07:38 AM.

  • 0

#19 Canuckles

Canuckles

    GMC Member

  • GMC Member
  • 46 posts
  • Version:GM:Studio

Posted 23 December 2012 - 07:54 PM

I'm just starting to wrap my head around the syntax and structure. It doesn't seem that drastically different than what I was doing before, so that's good news :)/>/>

The documentation in here is very well done!

Just out of curiosity, why is the player id limit listed as 255?

Edited by Canuckles, 23 December 2012 - 08:37 PM.

  • 1

#20 Canuckles

Canuckles

    GMC Member

  • GMC Member
  • 46 posts
  • Version:GM:Studio

Posted 26 December 2012 - 01:26 AM

Little mini update, the mysql++ documentation on the official site is making my head hurt.

Progressing very slowly, hopefully I'll have a working mysql login soon.

lol
  • 0

#21 Canuckles

Canuckles

    GMC Member

  • GMC Member
  • 46 posts
  • Version:GM:Studio

Posted 26 December 2012 - 09:51 AM

Before I completely lose my mind, would you be so kind as to elaborate on this:

To access MySQL:
-> mysql::execute("query string"); //Auto handles errors and returns the address to a result set


Is there a list of acceptable functions somewhere?

I tried the official mysql++ site, but couldn't figure anything out. How do we format the query string? Do you have an example of doing an insert into statement in mysql++?

Here's what I was trying to do:

mysql::execute("SELECT name FROM test WHERE id = '3'");

I'm guessing I have everything all wrong :S

Edited by Canuckles, 26 December 2012 - 10:32 AM.

  • 0

#22 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2527 posts
  • Version:GM8

Posted 02 March 2013 - 05:10 PM

You are correct in using SQL queries within that function. Take a look at the official MySQL documentation for a full list of acceptable commands.
  • 0

#23 Primoz128

Primoz128

    GMC Member

  • GMC Member
  • 323 posts
  • Version:GM:Studio

Posted 10 March 2013 - 03:23 PM

This suddendly pops up, after i messed up with c++ server + gm client from open source section of gm, but i gave up trying to figure out how to use the server <.<...

Tell me this explains itself easier...
  • 0

Looking for a coding partner for my space RTS solar conquest project. More information: http://gmc.yoyogames...opic=563123&hl=


#24 Orbitguy

Orbitguy

    UNS Lead Guy

  • GMC Member
  • 348 posts
  • Version:GM:Studio

Posted 01 December 2013 - 02:04 PM

The link... is dead. :(


  • 0

hahaaforum.jpgStick Legends Online - An Online Role Playing Adventure

 


#25 beeproductions

beeproductions

    Helping gmc users

  • GMC Member
  • 1322 posts
  • Version:GM:Studio

Posted 01 December 2013 - 11:17 PM

Really usefull content:).


  • 0

col-img1.pngcol-img4.png

bannersig.png

 

 


#26 Orbitguy

Orbitguy

    UNS Lead Guy

  • GMC Member
  • 348 posts
  • Version:GM:Studio

Posted 08 December 2013 - 05:19 PM

Bump, does anyone have this file?

 

Edit:  I actually found I have a copy in my GMC collection, so if anyone needs it hit me up. ;)  I also have another one, which has chat but no login/reg system.  lol


Edited by Orbitguy, 08 December 2013 - 06:04 PM.

  • 0

hahaaforum.jpgStick Legends Online - An Online Role Playing Adventure

 


#27 2DLuis

2DLuis

    Graphic Designer

  • GMC Member
  • 2527 posts
  • Version:GM8

Posted 13 December 2013 - 10:29 PM

Bump, does anyone have this file?

 

Edit:  I actually found I have a copy in my GMC collection, so if anyone needs it hit me up. ;)  I also have another one, which has chat but no login/reg system.  lol

 

I have fixed the link. We recently reset our server htdocs file structure and I forgot to upload this file. Link is working now.

 

Edit:

 

I just realized that the last compiler I used to compile all of the project's dependencies was Microsoft Visual Studio 2010.

If you are attempting to compile with a newer toolchain (which most of you are most likely), you will get conflicted compiler errors when linking to the libraries (39dll, hashlib, mysqlpp).

To fix this you must recompile these projects with your current toolchain. If you are unsure as to how to do this, PM me.


Edited by 2DLuis, 13 December 2013 - 10:34 PM.

  • 0