Created empty TCPNetworkManager; needs work, I don't even like the name
This commit is contained in:
+13
-1
@@ -16,6 +16,7 @@ Player:
|
|||||||
[graphical stuff]
|
[graphical stuff]
|
||||||
position
|
position
|
||||||
velocity
|
velocity
|
||||||
|
avatarName
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ PlayerManager:
|
|||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
Rememer: Top down programming/K.I.S.S.
|
Remember: Top down programming/K.I.S.S.
|
||||||
|
|
||||||
KeyDown:
|
KeyDown:
|
||||||
up:
|
up:
|
||||||
@@ -52,3 +53,14 @@ end
|
|||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
TCP systems
|
||||||
|
|
||||||
|
TCPNetworkManager:
|
||||||
|
Init //opens the TCP server socket, and allocates the socket set
|
||||||
|
Quit //close the TCP server socket, and free the socket set
|
||||||
|
AcceptConnections //accept new connections
|
||||||
|
Send //send to a specific client, closing the connection if an error occured
|
||||||
|
SendAll //send to all clients
|
||||||
|
CheckSockets //non-blocking
|
||||||
|
GetSocket() //get a specific socket
|
||||||
|
total connections in the packet
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include "server.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int, char**) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "Beginning server" << endl;
|
||||||
|
#endif
|
||||||
|
Server app;
|
||||||
|
try {
|
||||||
|
app.Init();
|
||||||
|
app.Proc();
|
||||||
|
app.Quit();
|
||||||
|
}
|
||||||
|
catch(exception& e) {
|
||||||
|
cerr << "Fatal error: " << e.what() << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "Clean exit" << endl;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+30
-11
@@ -1,19 +1,38 @@
|
|||||||
CXXFLAGS+=-std=c++11
|
#config
|
||||||
DFLAGS=-DDEBUG
|
CXXFLAGS+=-std=c++11 -DDEBUG
|
||||||
LIB=-lmingw32 -lSDL_net -lSDLmain -lSDL -lwsock32 -liphlpapi
|
LIB=-lmingw32 -lSDL_net -lSDLmain -lSDL -lwsock32 -liphlpapi
|
||||||
OBJ=
|
|
||||||
SRC=server.cpp
|
|
||||||
|
|
||||||
all: debug
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ=$(addprefix $(OBJDIR)/,main.o)
|
||||||
|
|
||||||
release: $(OBJ)
|
#output
|
||||||
$(CXX) $(CXXFLAGS) $(SRC) $(OBJ) $(LIB)
|
OUTDIR=out
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,a)
|
||||||
|
|
||||||
debug: $(OBJ)
|
#source
|
||||||
$(CXX) $(CXXFLAGS) $(DFLAGS) $(SRC) $(OBJ) $(LIB)
|
SRC=server.cpp tcp_network_manager.cpp
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(SRC) $(OBJ) $(LIB)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $(@) $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-$(RM) *.o *.a *.exe
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
|
|
||||||
unit:
|
unit:
|
||||||
$(CXX) $(CXXFLAGS) unit.cpp
|
|
||||||
|
|||||||
+28
-3
@@ -1,8 +1,33 @@
|
|||||||
|
#include "server.hpp"
|
||||||
|
|
||||||
#include "SDL/SDL.h"
|
#include "SDL/SDL.h"
|
||||||
#include "SDL_net/SDL_net.h"
|
#include "SDL_net/SDL_net.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <stdexcept>
|
||||||
|
|
||||||
int SDL_main(int, char**) {
|
using namespace std;
|
||||||
return 0;
|
|
||||||
|
Server::Server() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
Server::~Server() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::Init() {
|
||||||
|
if (SDLNet_Init()) {
|
||||||
|
throw(runtime_error("Failed to init SDL_net"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::Proc() {
|
||||||
|
bool running = true;
|
||||||
|
while(running) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::Quit() {
|
||||||
|
SDLNet_Quit();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef SERVER_HPP_
|
||||||
|
#define SERVER_HPP_
|
||||||
|
|
||||||
|
class Server {
|
||||||
|
public:
|
||||||
|
Server();
|
||||||
|
~Server();
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void Proc();
|
||||||
|
void Quit();
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#include "tcp_network_manager.hpp"
|
||||||
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef TCPNETWORKMANAGER_HPP_
|
||||||
|
#define TCPNETWORKMANAGER_HPP_
|
||||||
|
|
||||||
|
#include "SDL_net/SDL_net.h"
|
||||||
|
|
||||||
|
class TCPNetworkManager {
|
||||||
|
public:
|
||||||
|
TCPNetworkManager();
|
||||||
|
~TCPNetworkManager();
|
||||||
|
|
||||||
|
void Init(int maxConnections);
|
||||||
|
void Quit();
|
||||||
|
|
||||||
|
int AcceptConnections();
|
||||||
|
int CheckSockets();
|
||||||
|
|
||||||
|
int Send(int index, const void* data, int len);
|
||||||
|
int SendAll(const void* data, int len);
|
||||||
|
|
||||||
|
int OpenSocket(const char* host, int port);
|
||||||
|
TCPsocket GetSocket(int index);
|
||||||
|
int CloseSocket(int index);
|
||||||
|
|
||||||
|
int GetMaxConnections();
|
||||||
|
int GetCurrentConnections();
|
||||||
|
private:
|
||||||
|
TCPsocket serverSocket;
|
||||||
|
SDLNet_SocketSet socketSet;
|
||||||
|
int maxConnections, currentConnections;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user