diff options
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/main.cpp | 57 | ||||
| -rw-r--r-- | src/server/testclient.cpp | 110 |
2 files changed, 167 insertions, 0 deletions
diff --git a/src/server/main.cpp b/src/server/main.cpp new file mode 100644 index 0000000..846ec2b --- /dev/null +++ b/src/server/main.cpp @@ -0,0 +1,57 @@ + +#include <stdio.h> +#include <stdlib.h> +#include "../shared/util/hashmap.h" +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} + +//C++ things +#include <vector> +#include <thread> +#include <list> + +#include <string.h> // for strstr() +#include <nn.h> +#include <tcp.h> +#include <pair.h> + +#include <btBulletDynamicsCommon.h> +#include <cstdlib> + +#include "../shared/lua_api/common.h" +#include "../shared/lua_api/load_net.hpp" +#include "../shared/phys/physcommon.hpp" + +using namespace std; +using namespace chrono; + +lua_State* L; +void gameloop(){ + gameloop_phys(NULL); + gameloop_net(L); +} + +int main (){ + printf("Brok[en]gine Server\n"); + L = luaL_newstate(); + + phys_genesis(); + loadLLibs(L); + loadNetLibs(L); + int iErr = luaL_dofile(L,"../data/init.lua"); + if(iErr != 0){ + lua_error(L); + printf("Failed to open lua file:../data/init.lua\n"); + } + do{ + + gameloop(); + std::this_thread::yield(); + }while(true); + phys_shutdown(NULL); + + return 0; +} diff --git a/src/server/testclient.cpp b/src/server/testclient.cpp new file mode 100644 index 0000000..0aab8a2 --- /dev/null +++ b/src/server/testclient.cpp @@ -0,0 +1,110 @@ +// +// // Minimal C ZMQ Client example +// +// // Properties -> Linker -> Input -> Additional dependencies "libzmq.lib" +// // Properties -> Linker -> Input -> Additional dependencies "ws2_32.lib" +// +// #include <stdio.h> +// #include "zmq.h" +// +// +// #define WS_VER 0x0202 +// #define DEFAULT_PORT "5001" +// +// +// int main () +// { +// int retval; +// void *ctx, *s; +// zmq_msg_t query, reply; +// const char *query_string = "SELECT * FROM sometable, END SERVER", *reply_string; +// +// +// printf( "Initialise ZMQ context: \n" ); +// +// // Initialise ZMQ context, requesting a single application thread and a single I/O thread +// ctx = zmq_init(1); +// if( ctx == 0 ) { +// printf( "Error zmq_init: '%s'\n", zmq_strerror(errno) ); +// return 0; +// } +// +// while(1) { +// printf( "Create a ZMQ_REP socket: \n" ); +// // Create a ZMQ_REP socket to receive requests and send replies +// s = zmq_socket( ctx, ZMQ_REQ ); +// if( s == 0 ) { +// printf( "Error zmq_socket: '%s'\n", zmq_strerror(errno) ); +// break; +// } +// +// retval = zmq_connect( s, "tcp://localhost:5555" ); +// if( retval != 0 ) { +// printf( "Error zmq_connect: '%s'\n", zmq_strerror(errno) ); +// break; +// } +// +// +// // Allocate a message and fill it +// retval = zmq_msg_init_size( &query, strlen(query_string)+1 ); +// if( retval != 0 ) { +// printf( "Error zmq_msg_init_size: '%s'\n", zmq_strerror(errno) ); +// break; +// } +// +// memcpy( zmq_msg_data (&query), query_string, strlen (query_string)+1 ); +// +// printf( "Send Query: '%s'\n", query_string ); +// // Send Query +// retval = zmq_send( s, &query, 0 , 0); +// if( retval != 0 ) { +// printf( "Error zmq_send: '%s'\n", zmq_strerror(errno) ); +// break; +// } +// +// +// +// // Recover response +// zmq_msg_init(&reply); +// if( retval != 0 ) { +// printf( "Error zmq_msg_init: '%s'\n", zmq_strerror(errno) ); +// break; +// } +// +// printf( "Waiting for reply: \n"); +// +// // Receive reply, blocks until one is available +// retval = zmq_recv( s, &reply, 0 , 0); +// if( retval != 0 ) { +// printf( "Error zmq_recv: '%s'\n", zmq_strerror(errno) ); +// break; +// } +// +// // Process the reply +// reply_string = (const char *)zmq_msg_data(&reply); +// printf("Server reply: '%s'\n", reply_string); +// +// +// // Free message memory +// zmq_msg_close(&reply); +// +// break; +// } +// +// +// // Close connection +// if( s != 0) { +// printf( "Close connection \n"); +// retval = zmq_close(s); +// if( retval != 0 ) { +// printf( "Error zmq_close: '%s'\n", zmq_strerror(errno) ); +// } +// } +// +// // Release library resources +// retval = zmq_term(ctx); +// +// printf( "All Done \n" ); +// +// return 0; +// } |
