Jump to content

  • Log In with Google      Sign In   
  • Create Account

rogerdv

Member Since 18 May 2003
Offline Last Active Oct 02 2014 11:22 AM

Topics I've Started

What can be scripted and what should not in a server?

18 September 2014 - 08:01 AM

I have a doubt about using scripting languages like Lua to implement some stuff in a server, specifically player skills/spells. Is it wise to script such things or should I avoid scripts at all in the server design? What can be scripted and what should definitely not be scripted?

 


sqlite as db backend for mmorpg?

15 September 2014 - 07:16 AM

Usually, I tend to favour Postgresql for my server tests, but last night I was thinking about trying something different (not MySQL). Is it feasible to use Sqlite for MMORPG servers in terms of scalability, perfomance, etc?


my first gl 3 app: displaying a cube

20 May 2014 - 09:45 AM

Im trying to learn opengl 3 and I started by the traidtional triangle program. But I tried to improve it to display a cube, it doesnt shows anything. Here is the relevant code:

//the shaders
const char* vertex_shader =
"#version 150\n"
"in vec3 vp;"
"void main () {"
"  gl_Position = vec4 (vp, 1.0);"
"}";

const char* fragment_shader =
"#version 150\n"
"out vec4 frag_colour;"
"void main () {"
"  frag_colour = vec4 (0.5, 0.0, 0.5, 1.0);"
"}";

//the cube coordinates
GLfloat box[] = {  
	0.0f, 0.0f, 0.0f,
	1.0f, 0.0f, 0.0f,
	1.0f, 1.0f, 0.0f,
	0.0f, 1.0f, 0.0f,
	0.0f, 0.0f, -1.0f,
	1.0f, 0.0f, -1.0f,
	1.0f, 1.0f, -1.0f,
	0.0f, 1.0f, -1.0f
};

// Create and bind the VBO for the vertices.
    glGenBuffers(1, &g_verticesVBO);
    glBindBuffer(GL_ARRAY_BUFFER, g_verticesVBO);

    // Transfer the vertices from CPU to GPU.
    glBufferData(GL_ARRAY_BUFFER,  9 * sizeof(GLfloat), triangle, GL_STATIC_DRAW);
    //glBindBuffer(GL_ARRAY_BUFFER, 0);

  glGenVertexArrays (1, &g_vao);
  glBindVertexArray (g_vao);
  glEnableVertexAttribArray (0);
  glBindBuffer (GL_ARRAY_BUFFER, g_verticesVBO);
  glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL);

 //here we draw
 // wipe the drawing surface clear
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram (shader_programme);
glBindVertexArray (g_verticesVBO);
// draw points 0-3 from the currently bound VAO with current in-use shader
glDrawArrays (GL_QUADS, 0, 3); //also tried glDrawArrays (GL_QUADS, 0, 8); 
SDL_GL_SwapWindow(mainwindow);

Can somebody see what Im doing wrong here?


data structure for client list

27 February 2014 - 11:51 AM

I have started an educational project to learn about networking. I built a small server using enet that receives UDP packets and replies to clients, next step is to actually have multiple connected clients. I dont plan to create my own WoW killer mmorpg, but I would like to learn the right way to do things. I was plannnig to use an std::map to eep the list of clients indexed by their ip address, but then I thought that it wouldnt be optimal when the server needs to find client neighbors to propagate changes (I think that kdtrees are the right data structure to optimize that). Then I thought that I should have an  std::map indexed by IP and a kdtree with "visible" entities. And finally, I realized that using IPs mnaybe is not a wise way to index clients, because it would limit connections  to one per IP. What is the correct approach to this problem?

 


first steps with enet

10 February 2014 - 09:34 AM

I decided to invest some time on enet (as it seems to bee the best documented) and networks. I took the tutorial as base to make my own simple client/server test:

This is the server main code:

address.host = ENET_HOST_ANY;
	/* Bind the server to port 1234. */
	address.port = 3234;
	server = enet_host_create (& address /* the address to bind the server host to */,
	32 /* allow up to 32 clients and/or outgoing connections */,
	2 /* allow up to 2 channels to be used, 0 and 1 */,
	0 /* assume any amount of incoming bandwidth */,
	0 /* assume any amount of outgoing bandwidth */);
	if (server == NULL) {
		cout << "An error occurred while trying to create an ENet server host.\n";
		exit (EXIT_FAILURE);
	}

	ENetEvent event;
	bool stop = false;
	cout << "Starting server"<<endl;
	while (!stop){
		enet_host_service (server, & event, 0);
		if (event.type ==ENET_EVENT_TYPE_CONNECT) {
				cout <<"A new client connected from "<<	event.peer->address.host<<":" <<event.peer->address.port<<endl;
				/* Store any relevant client information here. */
				//event.peer -> data = "Client information";
		} else if (event.type ==ENET_EVENT_TYPE_RECEIVE) {
				cout << "A packet was received"<<endl;				
				/* Clean up the packet now that we're done using it. */
				enet_packet_destroy (event.packet);
		} else if (event.type ==ENET_EVENT_TYPE_DISCONNECT) {
				cout << " disconected " <<event.peer -> data<<endl;
				/* Reset the peer's client information. */
				event.peer -> data = NULL;
				stop = false;
		} //if
	} //while

And this is the relevand client code:

ENetHost * client;
	client = enet_host_create (NULL /* create a client host */,
	1 /* only allow 1 outgoing connection */,
	2 /* allow up 2 channels to be used, 0 and 1 */,
	57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */,
	14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */);
	if (client == NULL)	{
		cout<< "An error occurred while trying to create an ENet client host.\n";
		exit (EXIT_FAILURE);
	}

	ENetAddress address;
	ENetEvent event;
	ENetPeer *peer;
	/* Connect to some.server.net:1234. */
	enet_address_set_host (& address, "localhost");
	address.port = 3234;
	/* Initiate the connection, allocating the two channels 0 and 1. */
	peer = enet_host_connect (client, & address, 2, 0);
	if (peer == NULL)	{
		cout<< "No available peers for initiating an ENet connection.\n";
	exit (EXIT_FAILURE);
	}
	/* Wait up to 5 seconds for the connection attempt to succeed. */
	if (enet_host_service (client, & event, 5000) > 0 &&
		event.type == ENET_EVENT_TYPE_CONNECT){
		cout <<"Connection to localhost:3234 succeeded.";
		/* Create a reliable packet of size 7 containing "packet\0" */
		ENetPacket * packet = enet_packet_create ("ok",	strlen ("ok") + 1, ENET_PACKET_FLAG_RELIABLE);
		enet_peer_send (peer, 0, packet);
		enet_peer_disconnect (peer, 0);
	}	else {
	/* Either the 5 seconds are up or a disconnect event was */
	/* received. Reset the peer in the event the 5 seconds */
	/* had run out without any significant event. */
		enet_peer_reset (peer);
		cout <<"Connection to some.server.net:3234 failed.";
	}

The problem is that the client reports that it connected successfully, but the server does not notify of any connection or packet received. I have checked the code several times and cant find any logical error, so probably Im missing some aspect not documented on the tutorials. Can somebody give me an idea?


PARTNERS