[Anet] I´ve a VServer.. but how to connect?

Posted By: Espér

[Anet] I´ve a VServer.. but how to connect? - 01/01/11 21:20

Hi there, i´ve a small big problem..

I own a Virtual Server at Hosteurope. Now, with the help of the manual, i created an ANet Testproject:
Click to reveal..

Code:
#include <acknex.h>
#include "anet.h"
#include "default_anet.c"
#include "dr_template.c"
#include "players.c"



#define PRAGMA_PATH "ANetTemplatesProfessional/internetserverlist"

#include "inet_template.c"


FONT* arialer = "Arial#32b";

PANEL* digitaler =
{
	pos_x = 10;
	pos_y = 500;
	flags = SHOW;
	digits(0,0,"Drücke [1] für Server erstellen oder [2] für Client erstellen", arialer, 1, 0);
	digits(0,34,"Drücke [F11] um das Anet Debug anzuzeigen", arialer, 1, 0);
}




//======================================================================================================================================
// ALLGEMEINE VARIABLEN
//======================================================================================================================================
var i;
var max_players = 32;
var players[33];
var glob_port = 2300;


//======================================================================================================================================
// SERVER AUFBAUEN
//======================================================================================================================================
function connected(var sender, STRING* msg) 
{ 
	//... 
	error("Server hergestellt");
} 

function disconnected(var sender, STRING* msg) 
{ 
	//... 
}

function initial_server()
{
	enet_svset_event(EVENT_CONNECTED,"connected"); 
	enet_svset_event(EVENT_DISCONNECTED,"disconnected");
	enet_init_server(2300,4,""); // Port, Spielerzahl, Passwort
}


//======================================================================================================================================
// CLIENT AUFBAUEN
//======================================================================================================================================
function client_connected(var sender, STRING* msg) 
{ 
	//... 
	error("Client hergestellt");
} 

function client_disconnected(var sender, STRING* msg) 
{ 
	//... 
}

function initial_client()
{
	enet_clset_event(EVENT_CONNECTED,"client_connected"); 
	enet_clset_event(EVENT_DISCONNECTED,"client_disconnected");
	enet_init_client("178.77.69.66",2300,"");  // Host, Port, Passwort   - 178.77.69.66
}



//======================================================================================================================================
// SPIELSTART
//======================================================================================================================================
void main()
{
	fps_max = 50;
	video_mode = 8;
	d3d_antialias = 9;
	wait(1);
	enet_init();
	for(i=0;i<max_players;i++) {players[i] = 0;}
	level_load(NULL);
	wait(3);
	
	
	while(1)
	{
		if(key_1 == 1)
		{
			initial_server();
			//			enet_init_server(glob_port,4,""); // Port, Spielerzahl, Passwort
		}
		else if(key_2 == 1)
		{
			initial_client();
			//			enet_init_client("localhost",glob_port,""); // Host, Port, Passwort
		}
		wait(1);
	}
}




1 = Start Server
2 = Start Client



Like you see, i added the IP of my VServer to this Thing. Published, added the Anet keyfile and OpenGL32..something.. and sent it to my friend.


But it doesn´t matter what we are doing.. We can´t get a connection to each other...


Question:
How am i able to connect via server (there´s nearly nothing to it in the manual...)




Ps.: The Anet manual is extremely.. meagerly in infos...
Posted By: Rasch

Re: [Anet] I´ve a VServer.. but how to connect? - 01/01/11 21:48

Have you started the .exe file on your "VirtualServer"? Because if nothing is running on your VirtualServer there´s no server.

Are you allowed to run this application ona VServer on Hosteurope? I´m sure you need to ask them if this is possible and allowed. Maybe they need to forward the ports for you..

More informations please grin
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/01/11 21:50

nope.. didn´t started it there...
But i tried.. and it says "no mouse found"

I´ve not really an idea what i need to do.. it´s the first try on MP for me.

Posted By: Rasch

Re: [Anet] I´ve a VServer.. but how to connect? - 01/01/11 22:30

I´m not sure if you can run a 3D Apliaction on a Virtual Server. Better contact Hosteurope and ask them if you can run something like that.
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/01/11 22:36

long lives 24/7 support..

BUT.. it´s not working.

Is there a way to create something like a list of Games (servers) from other players.. so the clients don´t need to type in the server ip everytime..?
Posted By: Dark_samurai

Re: [Anet] I´ve a VServer.. but how to connect? - 01/01/11 23:11

Your problem has nothing to do with ANet. If Gamestudio can't start on your Virtual Server because no mouse is found ANet isn't even loaded wink
You could try to run the engine in console mode. Look into the manual under video_mode (set it to 0). This was also mentioned in the manual under enet_init_server(). Also why you need to do port forwarding is described in the manual (see introduction). Just read through it. And if you are new to MP programming, also give the workshops on the ANet homepage a try.

Quote:
Is there a way to create something like a list of Games (servers) from other players.. so the clients don´t need to type in the server ip everytime..?


Yes. Just open a Webserver (like Apache) on your virtual server and implement a server list database (SQL) that is accessed via HTTP (PHP). You can make use of ANet's built in htttp functions.
ANet also has a ready to use template that does the work for you. But I would advice you to do this in the last step of your game. First try to make the basics working (connecting, smooth playermovement,...). Then try to extend it with more advanced features.
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/01/11 23:14

ah.. ok...

Uhmm. actually.. i can connect local.. but still not to my friend (written my ip into enet_init_client)...

i found my ip via > http://www.wieistmeineip.de/ <, but i can´t connect..

Click to reveal..

Code:
#include <acknex.h>
#include "anet.h"
#include "default_anet.c"



FONT* arialer = "Arial#32b";

PANEL* digitaler =
{
	pos_x = 10;
	pos_y = 500;
	flags = SHOW;
	digits(0,0,"Drücke [1] für Server erstellen oder [2] für Client erstellen", arialer, 1, 0);
	digits(0,34,"Drücke [F11] um das Anet Debug anzuzeigen", arialer, 1, 0);
}




//======================================================================================================================================
// ALLGEMEINE VARIABLEN
//======================================================================================================================================
var i;
var max_players = 32;
var players[33];
var glob_port = 2300;


//======================================================================================================================================
// SERVER AUFBAUEN
//======================================================================================================================================
function initial_server()
{
	enet_svset_event(EVENT_CONNECTED,"svevent_connected"); 
	enet_svset_event(EVENT_DISCONNECTED,"svevent_disconnected");
	enet_init_server(glob_port,max_players,""); // Port, Spielerzahl, Passwort
	level_load("test.wmb");
	wait(3);
	enet_set_level("test.wmb"); //Levelfilename an Enet übertragen
}

function svevent_connected(var sender, STRING* msg, var length)
{ 
	//... 
	wait(1);
} 

function svevent_disconnected(var sender, STRING* msg, var length)
{ 
	//... 
	wait(1);
}


//======================================================================================================================================
// CLIENT AUFBAUEN
//======================================================================================================================================
function initial_client()
{
	enet_clset_event(EVENT_CONNECTED,"clevent_connected"); 
	enet_clset_event(EVENT_DISCONNECTED,"clevent_disconnected");
	enet_init_client("localhost",glob_port,"");  // Host/IP, Port, Passwort
	// local - localhost 
	// Server - 178.77.69.66
	// My - 84.57.165.124
}

function clevent_connected(var sender, STRING* msg, var length)
{ 
	//... 
	if(enet_get_connection() == CLIENT_MODE)
	{
		//Serverlevel laden (msg = vom Server gegebener Levelfilename)
		level_load(msg);
		wait(3);
		enet_ent_synchronize(); //synchronisiere entities
	}
} 

function clevent_disconnected(var sender, STRING* msg, var length)
{ 
	//... 
	wait(1);
}


//======================================================================================================================================
// SPIELSTART
//======================================================================================================================================
void main()
{
	fps_max = 500;
	video_mode = 8;
	d3d_antialias = 9;
	wait(1);
	enet_init();
	for(i=0;i<max_players;i++) {players[i] = 0;}
	
	var testings = 0;
	wait(1);
	while(testings == 0)
	{
		if(key_1 == 1)
		{
			initial_server();
			testings = 1;
		}
		else if(key_2 == 1)
		{
			initial_client();
			testings = 1;
		}
		wait(1);
	}
}




any idea why?
Posted By: SchokoKeks

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 12:05

Your router is blocking the incomming connection of your friend because of NAT.

You need to forward all traffic from the port you are using (glob_port = 2300) to the computer you have the server running on. For doing this, you need the local LAN-IP of that computer and have access to your router webinterface.

Unfortunately I can't give you a step-to-step guide as nearly every routers menu is different. Try this page, it has instructions for nearly every model:

http://portforward.com/
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 12:08

Port 2300 has port forwarding (done this a few weeks ago)
Port check says that the port 2300 is open ^.^

Ps.: On that site.. there´s nothing for an easyBox from Vodafon xD

actual code:
Click to reveal..

Code:
#include <acknex.h>
#include "anet.h"
#include "default_anet.c"



FONT* arialer = "Arial#32b";

PANEL* digitaler =
{
	pos_x = 10;
	pos_y = 500;
	flags = SHOW;
	digits(0,0,"Drücke [1] für Server erstellen oder [2] für Client erstellen", arialer, 1, 0);
	digits(0,34,"Drücke [F11] um das Anet Debug anzuzeigen", arialer, 1, 0);
}




//======================================================================================================================================
// ALLGEMEINE VARIABLEN
//======================================================================================================================================
var i;
var max_players = 32;
var players[33];
var glob_port = 2300;


//======================================================================================================================================
// SERVER AUFBAUEN
//======================================================================================================================================
function svevent_connected(var sender, STRING* msg, var length)
{ 
	//... 
	wait(1);
} 

function svevent_disconnected(var sender, STRING* msg, var length)
{ 
	//... 
	wait(1);
}

function start_server()
{
	enet_svset_event(EVENT_CONNECTED,"svevent_connected"); 
	enet_svset_event(EVENT_DISCONNECTED,"svevent_disconnected");
	enet_init_server(glob_port,max_players,""); // Port, Spielerzahl, Passwort
	level_load("test.wmb");
	wait(3);
	enet_set_level("test.wmb"); //Levelfilename an Enet übertragen
}


//======================================================================================================================================
// CLIENT AUFBAUEN
//======================================================================================================================================
function clevent_connected(var sender, STRING* msg, var length)
{ 
	//... 
	if(enet_get_connection() == CLIENT_MODE)
	{
		//Serverlevel laden (msg = vom Server gegebener Levelfilename)
		level_load(msg);
		wait(3);
		enet_ent_synchronize(); //synchronisiere entities
	}
} 

function clevent_disconnected(var sender, STRING* msg, var length)
{ 
	//... 
	wait(1);
}

function start_client()
{
	enet_clset_event(EVENT_CONNECTED,"clevent_connected"); 
	enet_clset_event(EVENT_DISCONNECTED,"clevent_disconnected");
	enet_init_client("84.57.165.124",glob_port,"");  // Host/IP, Port, Passwort
	// local - localhost 
	// Server - 178.77.69.66
	// My - 84.57.165.124
}


//======================================================================================================================================
// SPIELSTART
//======================================================================================================================================
void main()
{
	fps_max = 500;
	video_mode = 8;
	d3d_antialias = 9;
	wait(1);
	enet_init();
	for(i=0;i<max_players;i++) {players[i] = 0;}
	
	var testings = 0;
	wait(1);
	while(testings == 0)
	{
		if(key_1 == 1)
		{
			start_server();
			testings = 1;
		}
		else if(key_2 == 1)
		{
			start_client();
			testings = 1;
		}
		wait(1);
	}
}



Posted By: Dark_samurai

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 13:15

If you can connect local and you have the correct internet ip used for the connection than the problem is not ANet related. It's a networking problem caused by your router and/or firewall.

What protocol is forwarded? UDP or TCP? You should allow port 2300 over UDP.

Also try to turn off your firewall (on the client and the server).
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 13:17

firewall is turned off.. forwarding is on for TCP&UDP

IP is correct (a friend tried to connect).. Just That code from me, won´t give a connection..
Posted By: SchokoKeks

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 13:25

Also make sure that you and your friend are using the exact same published version of the game. Even removing an unused variable or function will make the new script incompatible to the old one. If you need a different code on client and server, use anet_use_handles(0).

Also, you can try to load the server IP from a text file so you don't have to chance it in the code every time.
And might try to set a password. Its just that I've never tried using an empty string, maybe there's a bug.

EDIT: Still, dark_samurai is right. If the connection works locally, but not over the internet, its usually not ANets fault but your firewall/router. Do you have a firewall? If using the build in windows firewall, make sure it doesn't block the server.
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 13:37

HA.. Got it to work (thanks to puppeteer)..

I changed nothing.. but a connection between him and me is working o.O
Posted By: Dark_samurai

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 14:10

To your virtual server problem, try to set video_screen = 0; (it's not video_mode, sorry for the wrong information; changed that in the manual). The engine should start then.
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 14:38

hmm..k.. but how so say the servergame, to start as server without changing the code?
Posted By: Rei_Ayanami

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 14:39

You have not read any workshops yet, have you?
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 14:45

i read it.. but if i change the code, the game versions are not the same...

I tried to start a server directly at startup for the servergame version..
(I mean.. the ANet manual isn´t saying any word about, how to connect to a server and how to code it.. it just gives help for PC<>PC or local games..)

But it just crashes again with "No mouse found" o.O
Posted By: Rei_Ayanami

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 14:47

You know that you can start code with different parameters?

Just check them with command_str [Look into the GS Manual) and than start your game as a server or a client via Code.
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 14:51

i nver used the A8 standard Online functions.. so.. the manual isn´t really clear for me..
(i´m happy that Anet connects now.. ^_^")

So i never used commands...
Posted By: Rei_Ayanami

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 15:03

-.-

Why don't you even look for it in the manual?

This STRING(!!) has nothing to do with multiplayer -.-'
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 15:07

that doesn´t change the situation.. that i never used commands... so be a bit more friendlier.. i use them for the first time -.-
Posted By: Dark_samurai

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 15:21

A command line is a string that is passed to the application at it's start. This way you can tell the application how to start before the application is loaded.
You could make an option that could be "-ANetServer" and if that option is set, you start the application in video_screen = 0; mode and initialize the server.

Example code:
Code:
function main()
{
   if (str_stri(command_str,"-ANetServer"))
   {
      video_screen = 0;
      StartServer();
   }
   else
   {
      StartClient();
   }
}



Now how can you pass the command line option to your application?

There are 2 ways:

1) During development through SED:
Go in SED under Options->Preferences. There is an text box where you can add "-ANetServer"

2) After publishing:
Create a batch file (.bat) with the text editor and insert the following line:
YourAppName.exe -ANetServer
(please correct me if I'm wrong, I'm not totally sure about the syntax!)
Save the .bat file in the same folder as the .exe. And double click on the .bat to start the application.
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 15:27

I startet the Batch at my server.. the white loading window appears for a break of a second (shows "no mouse found") and the game closes...
Posted By: Dark_samurai

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 15:31

Maybe there is an option for gamestudio to start even if no mouse is found. I don't know (you could try to search this in the forum and in the manual).

If you find no informations you could ask that in the Lite-C part of the forum or ask the developer (should be the last step, if nobody else knows the answer).
Posted By: Superku

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 15:52

Command line option:
"-nm
Disables the mouse."

Should help.
Posted By: Espér

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 16:12

ok.. now it shows

"Mouse Found".. and closes immidiately
Posted By: Dark_samurai

Re: [Anet] I´ve a VServer.. but how to connect? - 01/02/11 16:43

Does it work on your system at home with -nm -ANetServer?
Posted By: Espér

Re: [Anet] My first try at a Chat System.. some problems.. - 01/02/11 18:12

i think i´ll do the server stuff if i understand Anet a bit better..

I´ve two new problems..


1.) i wrote a little Chat system. it works really well.. BUT.. after a bit of time, Acknex crashs without an error, it just says "Acknex isn´t working anymore"...
Edit: I found out.. If i, as starter, write something when a client is online too.. the client crashes... Same thing if the client writes.. my game crashes..
Is there a way to stop that?

2.) Is there a way to call a string from the server? I just found enet_send_string...
Or a way to ask from the game-starter, if a client has entered.. and then send the string again?


Here´s my Chatcode:
Click to reveal..

Code:
function str_makeempty(var signcounter) //Empty the chat_in and fill it with a given number of spaces
{
	str_cpy(chat_in, "");
	while(signcounter > 0)
	{
		str_cat(chat_in, " ");
		signcounter -= 1;
	}
}

function wo_makeempty(var signcounter) //Empty the write_over and fill it with a given number of spaces
{
	str_cpy(write_over, "");
	while(signcounter > 0)
	{
		str_cat(write_over, " ");
		signcounter -= 1;
	}
}

void check_chathigh() // Check the high of the chat, and delete the upper rows if it is to high.
{
	while(chat_check != 0)
	{
		if(chatpattern.pos_y < max_high)
		{
			delete_pos = str_stri(chatlog,"\n");
			if(delete_pos)
			{
				str_clip(chatlog,delete_pos);
				chatpattern.pos_y = max_high;
			}
		}
		chat_check -= 1;
	}
	chat_check = 0;
}

void write_in() // Write received strings into the shown chatlog
{
	if(str_cmpi(write_login, "") == 0) // write if a client has entered
	{
		str_cat(chatlog, write_login);
		str_cat(chatlog, "\n");
		str_cpy(write_login, "");
	}
	if(str_cmpi(chat_sav, "") == 0) // write messages
	{
		str_cat(chatlog, chat_sav);
		str_cat(chatlog, "\n");
		str_cpy(chat_sav, "");
	}
}

function start_chatsystem()
{
	// create login text
	str_cat(write_login, spielername);
	str_cat(write_login, " hat das Spiel betreten..! \n");
	enet_send_string("write_login", BROADCAST);
	
	// create variables and strings
	chatpattern.pos_y = screen_size.y - 84;
	chatwrite.pos_y = screen_size.y - 18;
	set(chatpattern, SHOW);
	set(chatwrite, SHOW);

	str_cpy(write_over, "< ");
	str_cat(write_over, spielername);
	str_cat(write_over, " >");
	str_cat(write_over, ": ");
	str_cpy(write_name, write_over);
	
	chatstart = 0;
	line_len = 0;
	delete_pos = 0;
	max_high = screen_size.y - 192;
	paragraph_len = str_len(write_over);
	max_len = 100 - paragraph_len;
	wait(1);
	str_makeempty(max_len);
	wo_makeempty(paragraph_len);
	
	while(1)
	{
		write_in();
		
		if(chatstart == 0 && inkey_active == 0 && key_m == 1)
		{
			inkey(chat_in);
			chatstart = 1;
		}
		else if(chatstart == 1 && inkey_active == 0)
		{
			str_cpy(chat_out, chat_in);
			line_len = str_len(chat_in);
			if(str_cmpi(chat_in, "\w "))   //====================================== WHISPER Chat
			{
				// Not implemented yet
				error("geflüstert!");
			}
			else                           //====================================== PUBLIC Chat
			{
				if(line_len > 50) // if the text has more than 50 signs
				{
					line_len -= 50;  // cutout the first 50 signs and send them.
					str_trunc(chat_in, line_len);
					str_cat(chat_sav, write_name);
					str_cat(chat_sav, chat_in);
					enet_send_string("chat_sav", BROADCAST);
					enet_send_var("chat_check", BROADCAST);
					write_in();
					wait(4);
					str_cpy(chat_sav, "");  // cutout the last signs and send them.
					str_cpy(chat_in, chat_out);
					str_clip(chat_in,50);
					str_cat(chat_sav, write_over);
					str_cat(chat_sav, chat_in);
					chat_check = 2;
					enet_send_string("chat_sav", BROADCAST);
					enet_send_var("chat_check", BROADCAST);
					write_in();
					wait(4);
				}
				else // 1 Line of text (less than 50 signs)
				{
					str_cat(chat_sav, write_name);
					str_cat(chat_sav, chat_in);
					wait(4);
					chat_check = 1;
					enet_send_string("chat_sav", BROADCAST);
					enet_send_var("chat_check", BROADCAST);
					write_in();
					wait(4);
				}
				
				
				
				str_makeempty(100 - paragraph_len); // empty the chat_in string
				str_cpy(chat_out, "");
				
			}
			chatstart = 0;
		}
		
		
		if(chat_check == 1)
		{
			chatpattern.pos_y -= 16;
			check_chathigh();
		}
		else if(chat_check == 2)
		{
			chatpattern.pos_y -= 32;
			check_chathigh();
		}
		
		wait(1);
	}
}




function start_spieler(var conect_type) // Let the player type in his Name
{
	namewrite.pos_x = (screen_size.x / 2) - 160;
	namewrite.pos_y = (screen_size.y / 2) - 32;
	textbitmaps.pos_x = namewrite.pos_x-20;
	textbitmaps.pos_y = namewrite.pos_y-24;
	set(namewrite, SHOW);
	set(textbitmaps, SHOW);
	inkey(spielername);
	while(inkey_active == 1){wait(1);}
	reset(namewrite, SHOW);
	reset(textbitmaps, SHOW);
	namewrite.pos_x = -5000;
	textbitmaps.pos_x = -5000;
	
	wait(2);
	if(conect_type == 2)
	{
		enet_set_playername(spielername);
	}
	wait(2);
	start_chatsystem();
}



Posted By: Dark_samurai

Re: [Anet] My first try at a Chat System.. some problems.. - 01/02/11 19:13

2) Look into enet_sv/clsend_event() I think it's exaclty what you need.

1) Please don't let the community search for coding mistakes if the code has already that size. Try to find out what is executed before it crashes (use the debugger or use the error() function to see what was called before the crash).
But I would advice you to use enet_sv/clsend_event() instead of enet_send_string(). It would make your code much easier and cleaner => also bug searching will be easier then laugh
Posted By: Espér

Re: [Anet] My first try at a Chat System.. some problems.. - 01/02/11 19:58

uhm.. i got it to work.. but only for the server.. the clients can´t read anything... *cry*

I really dn´t know what to need for wich connection type..
Code:
if(conecting_type == 2) //Send as Client
			{
				enet_clsend_event(18,chat_in,0,BROADCAST);
			}
			if(conecting_type == 1) //Send as Server/client
			{
				enet_svsend_event(16,chat_in,0,BROADCAST);
			}



And the manual is really really bad documented in that...


forget it.. got it to work .. however..
© 2024 lite-C Forums