there is now a player character and the world renders using a cammera
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
game_client.c
|
||||
server.c
|
||||
transactions.c
|
||||
)
|
||||
|
||||
60
source/server_source/game_client.c
Normal file
60
source/server_source/game_client.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "game_client.h"
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
int Connect(game_server* gs) {
|
||||
struct sockaddr_in serverAddr;
|
||||
serverAddr.sin_family = AF_INET;
|
||||
serverAddr.sin_port = htons(gs->info.port);
|
||||
int blocking_mode = 1;
|
||||
|
||||
|
||||
gs->socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
inet_pton(AF_INET, gs->info.ip, &serverAddr.sin_addr);
|
||||
|
||||
if(connect(gs->socket, (struct sockaddr*)&serverAddr, sizeof(serverAddr)) < 0) {
|
||||
ioctl(gs->socket, FIONBIO, &blocking_mode); // Shuld be 1
|
||||
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int Client_Send(game_server* gs,packet* packet) {
|
||||
int sendPacketSize = sizeof(int) + sizeof(int) + packet->size;
|
||||
unsigned char* buffer = malloc(sizeof(int) + sizeof(int) + packet->size);
|
||||
memcpy(buffer, &packet->packetTpye, sizeof(int));
|
||||
memcpy(buffer+sizeof(int), &packet->size, sizeof(int));
|
||||
memcpy(buffer+sizeof(int)+sizeof(int), &packet->packet, packet->size);
|
||||
|
||||
write(gs->socket, buffer, sendPacketSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Client_Recive(game_server* gs, packet* packet) {
|
||||
|
||||
if(read(gs->socket, &packet->packetTpye, sizeof(int)) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if(read(gs->socket, &packet->size, sizeof(int)) <= 0 ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
packet->packet = malloc(packet->size);
|
||||
|
||||
if(read(gs->socket, &packet->packet, packet->size) <= 0) {
|
||||
free(packet->packet);
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Disconnect(game_server* gs) {
|
||||
close(gs->socket);
|
||||
return 0;
|
||||
}
|
||||
24
source/server_source/game_client.h
Normal file
24
source/server_source/game_client.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef GAME_CLIENT_H
|
||||
#define GAME_CLIENT_H
|
||||
|
||||
#include "transactions.h"
|
||||
|
||||
typedef struct {
|
||||
const char* ip;
|
||||
int port;
|
||||
int id;
|
||||
} server_info;
|
||||
|
||||
typedef struct {
|
||||
int socket;
|
||||
server_info info;
|
||||
}game_server;
|
||||
|
||||
int Connect(game_server* gs);
|
||||
|
||||
int Send(game_server* gs,packet* packet);
|
||||
int Recive(game_server* gs, packet* pakcet);
|
||||
|
||||
int Disconnect(game_server* gs);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "server.h"
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
int start_server() {
|
||||
struct sockaddr_in server;
|
||||
int serverSock;
|
||||
|
||||
serverSock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(2223);
|
||||
server.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
if(bind(serverSock, (struct sockaddr*)&serverSock, sizeof(server)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
listen(serverSock, 4);
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
|
||||
typedef struct {
|
||||
int port;
|
||||
int id;
|
||||
} server_info;
|
||||
#include "transactions.h"
|
||||
|
||||
typedef struct {
|
||||
} client;
|
||||
typedef struct {
|
||||
} client_manager;
|
||||
|
||||
int start_server();
|
||||
|
||||
server_info start_server();
|
||||
|
||||
#endif // !SERVER_H
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "transactions.h"
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define PORT 2223
|
||||
#define IP_ADDRESS "127.0.0.1"
|
||||
|
||||
|
||||
int CreateTransaction(action *act) {
|
||||
|
||||
int bufferSize = sizeof(int)*3 + act->argsize;
|
||||
|
||||
//unsigned char* buffer = malloc(bufferSize);
|
||||
|
||||
//buffer[0] = act->id;
|
||||
//buffer[sizeof(int)*1] = act->action;
|
||||
//buffer[sizeof(int)*2] = act->argsize;
|
||||
//memcpy(&buffer[sizeof(int)*3], act->userArg, act->argsize);
|
||||
|
||||
|
||||
//free(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetTransaction(action *act) {
|
||||
|
||||
|
||||
int id;
|
||||
int action;
|
||||
int argsize;
|
||||
void* data;
|
||||
|
||||
|
||||
|
||||
act->id = id;
|
||||
act->action = action;
|
||||
act->argsize = argsize;
|
||||
act->userArg = data;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ProssesTransaction(action *act) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* =============================================================================
|
||||
* # Server Transactions.
|
||||
* Transactions in the contexts of a entity, is an action. This action could be
|
||||
* anything that my include moving, shooting, douging, etc.
|
||||
*
|
||||
* Transactions take an entity id, action id, argsize and user
|
||||
*
|
||||
*
|
||||
* =============================================================================
|
||||
* */
|
||||
#ifndef TRANSACTIONS_H
|
||||
|
||||
#define ENTITY_ACTION_MOVE_UP 1
|
||||
#define ENTITY_ACTION_MOVE_DOWN 2
|
||||
#define ENTITY_ACTION_MOVE_LEFT 3
|
||||
#define ENTITY_ACTION_MOVE_RIGHT 4
|
||||
|
||||
|
||||
typedef struct {
|
||||
int packetTpye, size;
|
||||
void* packet;
|
||||
}packet;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
int action;
|
||||
int argsize;
|
||||
void* userArg;
|
||||
}action;
|
||||
|
||||
int CreateTransaction(action* act);
|
||||
int GetTransaction(action* act);
|
||||
int ProssesTransaction(action* act);
|
||||
|
||||
#define TRANSACTIONS_H
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user