This commit is contained in:
2019-04-29 15:47:44 -05:00
parent 75423afd94
commit aa6df20681
6 changed files with 200 additions and 69 deletions
+15
View File
@@ -56,14 +56,29 @@ private:
void stop();
public:
/*
* Create an instance of client
*/
Client(
MODE mode,
int port,
std::string url,
std::function<void(SHAPE &S, MODE &M)> &update);
~Client();
/*
* Kill the server
*/
void kill();
/*
* Running
*/
bool running();
/*
* Send the shape encrypted or raw
*/
void send(bool encrypt, SHAPE shape);
};
} // namespace betacore
+104 -12
View File
@@ -31,13 +31,13 @@ private:
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
int MONITOR_WIDTH=1920;
int MONITOR_HEIGHT=1080;
const char *TITLE ;
int MONITOR_WIDTH = 1920;
int MONITOR_HEIGHT = 1080;
const char *TITLE;
bool KEEP_ALIVE = true;
bool SHOW_GRID = false;
SHAPE USER_CURRENT = NONE;
SHAPE GUST_CURRENT = NONE;
SHAPE GUST_CURRENT = NONE;
MODE ME;
bool KEY_UP_ARROW_ACTIVE = false;
bool KEY_DOWN_ARROW_ACTIVE = false;
@@ -46,46 +46,138 @@ private:
bool KEY_SPACE_ACTIVE = false;
bool KEY_RETURN_ACTIVE = false;
bool FULL_SCREEN = false;
Client* client = nullptr;
Client *client = nullptr;
public:
Game(MODE mode,
int port,
std::string url);
int port,
std::string url);
~Game();
int init();
int initGL();
/**
* Draws box for use with guest \ current screens
*/
void box();
/**
* Close the application
*/
void close();
/*
* Draw a grid on the screen (G key)
*/
void grid();
/*
* Paint the gl context
*/
void paint();
void events( SDL_Event &event );
/*
* SDL Context
*/
void events(SDL_Event &event);
/*
* On key down events
*/
void key_down(SDL_Keycode key_code);
/*
* On key up events
*/
void key_up(SDL_Keycode key_code);
void resize ( int width, int height );
/*
* Resize the window to width : height
*/
void resize(int width, int height);
/**
* Draw a filled triange
*/
void triangle();
/*
* Draw a filled or wireframe triangle
*/
void triangle(bool filled);
/*
* Draw a filled or wireframe square
*/
void square();
/*
* Draw a filled or wireframe square
*/
void square(bool filled);
/*
* Draw a filled or wireframe circle
*/
void circle();
/*
* Draw a filled or wireframe circle
*/
void circle(bool filled);
/*
* Draw a filled or wireframe pentagon
*/
void pentagon();
/*
* Draw a filled or wireframe pentagon
*/
void pentagon(bool filled);
/*
* Draw a wireframe rectangle
*/
void rectangle();
/*
* Draw a filled or wireframe cross
*/
void cross(bool filled);
/*
* Draw the key pad compass
*/
void compass();
/*
* Event call for up
*/
void on_key_up_arrow();
/*
* Event call for down
*/
void on_key_down_arrow();
/*
* Event call for left
*/
void on_key_left_arrow();
/*
* Event call for right
*/
void on_key_right_arrow();
/*
* Event call for space
*/
void on_key_space();
/*
* Event call for enter
*/
void on_key_enter();
void top_screen();
/*
* Draw user screen
*/
void user_screen();
/*
* Draw guest screen
*/
void guest_screen();
void update(SHAPE &s,MODE &m);
/*
* On update from network
*/
void update(SHAPE &s, MODE &m);
};
} // namespace betacore
#endif
+49 -18
View File
@@ -5,46 +5,77 @@
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <thread>
#include <utility>
#include <functional>
#include "common.hpp"
// LINUX SYSTEM CALLS :)
#include <sys/socket.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include <unistd.h>
namespace betacore
{
class Server
{
private:
fd_set rset;
fd_set rset;
bool online = false;
bool server_running= false;
bool server_running = false;
int port;
int server_socket;
std::vector<int> clients;
struct sockaddr_in server_address;
void start();
void shutdown();
void listener();
void read_socket(int client);
void forward_message(int client,char buffer[BUFFER_LENGTH] );
public:
Server(int port);
void off();
bool running();
/*
* Starts the server
*/
void start();
/*
* Shutdown Routine
*/
void shutdown();
/*
* Listen for connection and spawn a new thread
*/
void listener();
/*
* Read the socket, is blocking, but will block its own thread
*/
void read_socket(int client);
/*
* This will forward to all connected clients except the client fd given
*/
void forward_message(int client, char buffer[BUFFER_LENGTH]);
public:
/*
* Create a server on port
*/
Server(int port);
/*
* Turn it off
*/
void off();
/*
* Return true if the server is running
*/
bool running();
};
} // namespace betacore