Quick Super Noob Question about Connecting

Posted By: DLively

Quick Super Noob Question about Connecting - 02/24/15 09:14

I have covered the multiplayer tutorial and am trying to use it as a base to start something hopefully awesome... I have pro edition.

how do I allow someone to connect to my server? say my neighbor from their pc
Posted By: Reconnoiter

Re: Quick Super Noob Question about Connecting - 02/24/15 10:20

Open up the right ports.

Than just session_open and let him session_connect with your internet ip (unless you two have a lan connection). (check whatismyip.com or whatever it is called)

The more professional way is to get a website that saves server info and create a server list window that gets that info and shows it to people who want to join something. This would also let you names of servers, number of people in it etc.

Oh and be sure nothing blocks the game (like some antivirus software).
Posted By: DLively

Re: Quick Super Noob Question about Connecting - 02/24/15 10:59

Thanks Reconnoiter. I appreciate your help with this.

Quote:
Open up the right ports.

Can you give me an example? I've been researching this simple task for the last 5 hours smirk It really shouldn't be this difficult.

I have a website. How would I go about using it to connect people?
Posted By: MasterQ32

Re: Quick Super Noob Question about Connecting - 02/24/15 11:31

https://www.google.de/search?q=port+forwarding
Posted By: Reconnoiter

Re: Quick Super Noob Question about Connecting - 02/24/15 12:43

@DLively, np glad to be of help.

To add to what MasterQ32 said, also check dplay_port in the manual.

Quote:

I have a website. How would I go about using it to connect people?
, I have not done this myself yet but from what I have read is that you can use the http functions (since you have pro you can just use the gamestudio http functions, see manual for example) for saving and retrieving info on and from the site.
Iirc if you search on this forum for someting like 'server browser' or perhaps 'server list' you find some threads with some examples.
Posted By: DLively

Re: Quick Super Noob Question about Connecting - 02/25/15 00:09

Any Ideas why if I use a port checker it says my port is closed even though I followed several tutorials and know my port is or must be open...?

Moreover, with a port and port forwarder set up i still can't get my friend to load in to the game.
Posted By: DLively

Re: Quick Super Noob Question about Connecting - 02/25/15 00:25

I wanted to post my script and ask why it doesn't use my websites ip address as a server? Do I need to use port forwarding with a domains ip too? If so how do I set up port forwarding on my server?

Code:
#include <litec.h>
#include <acknex.h>
#include <acknet.h>
#include <windows.h>

STRING* devonlively_com= "1##.###.###.#5";//ip address of my website
STRING* temp_str="";
TEXT* ip_info={
layer = 1;pos_x = 10;pos_y = 10;string = temp_str;flags = SHOW;} 

...

function main() 
{
	dplay_port = 7777;
	
	if (!connection) { // not started with -cl / -sv -cl?
		if (!session_connect(app_name,devonlively_com)){ // no client found on the localhost?
			if(result == 0)session_open(app_name); // start as server
		}
	}

	do { wait(1); }
	while (dplay_status < 2); // wait until the session is opened or joined
	
	dplay_entrate = 4;  // 16 ticks/4 = 4 updates per second
	dplay_smooth = 0;   // dead reckoning not needed
	dplay_localfunction = 2;
	level_load (NULL);
	vec_set(camera.x, vector (-600, 0, 100)); // set a proper camera position

	if (connection & CONNECT_SERVER) { // this instance of the game runs on the server
		video_window(0,0,0,"Server");
		ent_create ("link_0.mdl",vector(100,50,40),player_move); // then create the red guard!
		str_cpy(temp_str,server_name);
		str_cat(temp_str," has the IP: ");
		str_cat(temp_str,server_ip);
		str_cat(temp_str," ");
		str_cat(temp_str,session_name);
		
		} else { // otherwise, it runs on a connected client
		video_window(0,0,0,player_name);
		random_seed(0); // allow random player positions
		ent_create ("link_0.mdl",vector(-100+random(200),-50+random(100),40),player_move); // create the blue guard
		str_cpy(temp_str,dplay_id);
	}
	
}

Posted By: DLively

Re: Quick Super Noob Question about Connecting - 02/25/15 01:35

OKay!

FInally moved forwards a bit.. a small tiny little but not insignificant step forward...

So I have my virtual server, and port forwarders disabled - and typing in my router given ip address into the session_connects second parameter in quotes I have my second pc running as a client finally...

Now I'd like it so that my second pc or neighbor or you yourself could join into my server.

How do I do this? is this done with port forwarding or vitual servers?
Posted By: Reconnoiter

Re: Quick Super Noob Question about Connecting - 02/25/15 12:54

Maybe this helps (found it in the tutorial workshop 25 mp):

Quote:

Hosting an online game
How can we set up our home PC so that people can play our online game over the internet? There are two problems. First, your PC is probably not directly connected to the Internet, but sits behind a router and a firewall. Second, the internet IP address of your PC will probably change all the time, dependent on your service provider. The solution to the first problem is Port Forwarding, to the second a DynDNS service. Here's a brief step by step instruction to set up an online game server.

Port forwarding directs all Internet data packets with a certain port address to a certain PC in your local network. Open the control panel of your router, and use the Port Forwarding function to assign your port address (set up with dplay_port or the -port command line option) to the local IP of your server. By default, the engine uses port 2300. Your local server IP can be read from the server_ip string, or found with the ipconfig utility. It normally starts with 192.168... Make sure to set up your network so that the local IP of your server is always the same.
Additionally to port forwarding, you need to open the same port in the Windows firewall of your server. Otherwise the traffic will pass the router, but will be blocked by your PC.
Once you've did that, and started the game in server mode, people can connect to your Internet address. They have to start the game in client mode and give your Internet IP address with the -ip command line option. Your Internet IP is assigned by your service provider - it's not the same as your local server IP. You can find your Internet IP through websites like www.whatismyip.com. Note that you can probably not connect to your own Internet IP unless your router supports NAT loopback. So you need to ask other people to test the connection.
Now people can join your game, but they need always to call you before and ask for your current Internet IP. For preventing this, get a persistent domain from a free DynDNS service like www.dyndns.org. If your router supports DynDNS domains, it can be set up to automatically connect to the service and submit the new Internet IP whenever it has changed. Otherwise you need to install a DynDNS client on your PC.
Posted By: EpsiloN

Re: Quick Super Noob Question about Connecting - 03/12/15 08:09

About the Servers listing, I've also never done this, but I'm planning it for my next project.

The theory is this:
Every play that clicks "Start server" sends URL GET parameters to my webpage, a certain .php file that records his IP, PORT, Server name, Players in server, map name in a MySQL table.
Then, every client that clicks on "Servers list" will send GET method parameters to my webpage, again a certain .php file, that will spit out all servers recorded in the MySQL table as text.
The client's game will parse this text to separate the servers and show them on screen. Once the player clicks "Join", he'll use the IP that was given by my website for that particular server to connect a session.
When a server is closed, it will again send data to my website to get it off the list. Also, each time a client disconnects, the server will send data to modify the information in the table to show accurate players count for that server.

All this is done with a MySQL table and basic PHP.

If you don't know what GET parameters are, search on google. GET is the vars sent with the website address in the URL input box on your Internet Explorer.

The only hard part is parsing the returned text. Not that its hard, but there are countless ways to implement that...
Posted By: DLively

Re: Quick Super Noob Question about Connecting - 04/05/15 16:43

Quote:

About the Servers listing, I've also never done this, but I'm planning it for my next project.

The theory is this:
Every play that clicks "Start server" sends URL GET parameters to my webpage, a certain .php file that records his IP, PORT, Server name, Players in server, map name in a MySQL table.
Then, every client that clicks on "Servers list" will send GET method parameters to my webpage, again a certain .php file, that will spit out all servers recorded in the MySQL table as text.
The client's game will parse this text to separate the servers and show them on screen. Once the player clicks "Join", he'll use the IP that was given by my website for that particular server to connect a session.
When a server is closed, it will again send data to my website to get it off the list. Also, each time a client disconnects, the server will send data to modify the information in the table to show accurate players count for that server.

All this is done with a MySQL table and basic PHP.

If you don't know what GET parameters are, search on google. GET is the vars sent with the website address in the URL input box on your Internet Explorer.

The only hard part is parsing the returned text. Not that its hard, but there are countless ways to implement that...


Thanks dude, This is awesome! This makes good sense, I just need to put the theory to work for myself now. I've been building websites so php and mysql is like riding a bike grin Edit: (if you know how to ride a bike I suppose)
Posted By: EpsiloN

Re: Quick Super Noob Question about Connecting - 04/06/15 10:19

No problem laugh I will be doing the same thing soon, so if you have any problems contact me and I'll try to help.

Also, here's a long forgotten MMO project I was working on, as an example of a character creation with a PHP and MySQL system:
Code:
STRING* character_creation_str="";
STRING* client_username_str="";
STRING* client_password_str="";
function create_character()
{
	character_creation = 1;
	str_cpy(character_creation_str,"op=7&user=");
	str_cat(character_creation_str,client_username_str);
	str_cat(character_creation_str,"&pass=");
	str_cat(character_creation_str,client_password_str);
	str_cat(character_creation_str,"&app=0000000000&pos=0000000x0000000x0000000");
	var createchar_http_id = http_sendpost("http://www.mesetts.com/game_req.php",character_creation_str);
	while (!http_status(createchar_http_id)) { wait(1); }	//wait for the server to reply
	if (http_status(createchar_http_id) == 1)					//transfer successful?
	{
		http_result(createchar_http_id,character_creation_str);	//get the replied IP
		if(str_cmp(character_creation_str,"41") == 1)
		{
			info_num = 13;
			str_cpy((info_txt.pstring)[0],"Character created!\nEntering game...");
			pan_controller(info_ok , SHOW_PAN);
		}
		else
		{
			info_num = 12;
			str_cpy((info_txt.pstring)[0],"Could not create. Please,\ncontact the administrator immediately!\nError code: ");
			str_cat((info_txt.pstring)[0],character_creation_str);
			pan_controller(info_ok , SHOW_PAN);
		}
	}
	else
	{
		info_num = 12;
		str_cpy((info_txt.pstring)[0],"Could not connect to database server.");
		pan_controller(info_ok , SHOW_PAN);
	}
	http_free(createchar_http_id);									//always cleanup the httpid!
}



And the PHP part:
Code:
if($operation == 7) {				// If register request
	if(isset($_GET['user'])) {		// If user received
		$user = $_GET['user'];		// Get it
	}
	else {
		echo '43';			// Else return 5 - no user posted
		return;
	}
	if(isset($_GET['pass'])) {		// If pass received
		$pass = $_GET['pass'];		// Get it
	}
	else {
		echo '44';			// Else return 6 - no pass posted
		return;
	}
	if(isset($_GET['app'])) {
		$app = $_GET['app'];
	}
	else {
		echo '48';
		return;
	}
	if(isset($_GET['pos'])) {
		$pos = $_GET['pos'];
	}
	else {
		echo '49';
		return;
	}

	$user = stripslashes($user);		// Strip slashes
	$pass = stripslashes($pass);
	$user = mysql_real_escape_string($user);	// Remove bad characters
	$pass = mysql_real_escape_string($pass);
	$app = stripslashes($app);
	$app = mysql_real_escape_string($app);
	$pos = stripslashes($pos);
	$pos = mysql_real_escape_string($pos);

	$mysqli_query_str="SELECT * FROM users WHERE nick='$user' and parola='$pass'";	// Prepare query
	$result=$mysqli->query($mysqli_query_str);					// Look for user

	// Mysql_num_row is counting table row
	$count=$result->num_rows;
	// If result matched $myusername and $mypassword, table row must be 1 row

	if($count==1){				// If match found
		$row = $result->fetch_assoc();
		if($row['character'] != null)
		{
			echo "46";		// Already present
			return;
		}
		else {
			$mysqli_query_str="INSERT INTO characters (appearance, position) VALUES('$app','$pos')";	// Prepare query
			$result=$mysqli->query($mysqli_query_str);							// Register user in database
			if($result) {
				$charid = $mysqli->insert_id;
				$mysqli_query_str='UPDATE users SET `character`="'.$charid.'" WHERE `nick`="'.$user.'" AND `parola`="'.$pass.'"';	// Prepare query
				$result=$mysqli->query($mysqli_query_str);							// Register user in database
				if($result) {
					echo "41";		// Success creating char and inserting
					//echo "<br />" . $charid . " | " . $result . "<br />" . $mysqli_query_str;
				}
				else {
					echo "40";		// Success creating/failed linking
					//echo "<br />" . $mysqli->error;
					return;
				}
			}
			else {
				echo "47";			// Failed creating
				return;
			}
		}
	}
	else {
		echo '45';			// Else - no user found / bad pass
		return;
	}
}



pan_controller is a function that shows/hides my panels in this case...

Don't laugh at my PHP laugh it was a long time ago...
Posted By: DLively

Re: Quick Super Noob Question about Connecting - 04/06/15 13:59

Thank you! This will be great to learn from. Better a little late, than never grin

Your php is not bad enough to laugh at tongue You may already know this but you can place functions in functions.
Code:
$user = stripslashes(mysql_real_escape_string($user));// Strip slashes & Remove bad characters
$pass = stripslashes(mysql_real_escape_string($pass));

....

$result=$mysqli->query("SELECT * FROM users WHERE nick='$user' and parola='$pass'");


I like php because of how 'dynamic' the usability of the syntax is.

Cheers laugh
Posted By: EpsiloN

Re: Quick Super Noob Question about Connecting - 04/07/15 10:32

Now I know, years ago I didn't laugh I also like the flexibility PHP has that is missing in Lite-C, but at least Conitec added multidimensional arrays, unlimited local arrays and passing any number of arguments... grin That was my biggest pain back in the days...it was extremely limited...
© 2024 lite-C Forums