+++ /dev/null
-#define VG_NO_STEAM
-#define VG_SERVER
-#include "vg/vg.h"
-#include "vg/vg_opt.h"
-#include "vg/vg_log.h"
-
-#include "world_info.h"
-#include "highscores.h"
-#include "highscores.c"
-
-int main( int argc, char *argv[] ){
- u32 pool_size = 250000,
- playerinfo_pool_size = 10000;
-
- vg_set_mem_quota( 100*1024*1024 );
- vg_alloc_quota();
- int ready = 0;
-
- char *arg;
- while( vg_argp( argc, argv ) ){
- if( (arg = vg_long_opt_arg( "max-records" )) ){
- pool_size = atol(arg);
- }
- if( (arg = vg_long_opt_arg( "max-users" )) ){
- playerinfo_pool_size = atol(arg);
- }
-
- if( (arg = vg_arg()) ){
- if( ready ){
- vg_fatal_error( "Only one database can be read at a time\n" );
- }
-
- highscores_init( pool_size, playerinfo_pool_size );
- if( !highscores_read( arg ) )
- return 0;
- ready = 1;
- }
-
- if( vg_long_opt("list_tables") ){
- if( !ready )
- vg_fatal_error( "Not ready\n" );
-
- for( u32 i=0; i<vg_list_size(track_infos); i ++ ){
- vg_info( "%u: %s\n", i, track_infos[i].name );
- }
- }
-
- if( (arg = vg_long_opt_arg("records-csv")) ){
- char buf[512];
- struct highscore_system *sys = &highscore_system;
- for( u32 i=0; i<vg_list_size(track_infos); i ++ ){
- snprintf( buf, 512, "%03u-%s", i, arg );
- FILE *records = fopen( buf, "w" );
-
- highscore_track_table *table = &sys->dbheader.tracks[i];
- aatree_ptr it = aatree_kth(&sys->aainfo_time,table->root_time,0);
- while( it != AATREE_PTR_NIL ){
- highscore_record *inf = aatree_get_data( &sys->aainfo_time, it );
- fprintf( records, "%hu,%hu,%hu,%lu,%u\n",
- inf->trackid,
- inf->points,
- inf->time,
- inf->playerid,
- inf->datetime );
- it = aatree_next( &sys->aainfo_time, it );
- }
- fclose( records );
- }
- }
-
- if( (arg = vg_long_opt_arg("users-csv")) ){
- FILE *records = fopen( arg, "w" );
- struct highscore_system *sys = &highscore_system;
- aatree_ptr it =
- aatree_kth( &sys->aainfo_playerinfo_playerid,
- sys->dbheader.playerinfo_root,
- 0 );
-
- while( it != AATREE_PTR_NIL ){
- highscore_playerinfo *inf = aatree_get_data(
- &sys->aainfo_playerinfo_playerid, it );
-
- fprintf( records, "%lu,%s\n", inf->playerid, inf->nickname );
- it = aatree_next( &sys->aainfo_playerinfo_playerid, it );
- }
- fclose( records );
- }
- }
-}
+++ /dev/null
-#if 0
-#include "ent_portal.h"
-#include "addon.h"
-#include "pointcloud.h"
-
-static void ent_portal_pointcloud_load_thread(void *_){
- char path_buf[4096];
- vg_str path;
- vg_strnull( &path, path_buf, 4096 );
- addon_get_content_folder( global_portal.display_world, &path );
- vg_strcat( &path, "/preview.bin" );
-
- vg_linear_clear(vg_mem.scratch);
- u32 size;
-
- void *data = vg_file_read( vg_mem.scratch, path_buf, &size );
- if( data ){
- if( size < sizeof(pointcloud_buffer) ){
- vg_async_call( pointcloud_clear_async, NULL, 0 );
- return;
- }
-
- vg_async_item *call = vg_async_alloc(size);
- pointcloud_buffer *pcbuf = call->payload;
- memcpy( pcbuf, data, size );
-
- u32 point_count = (size-sizeof(pointcloud_buffer)) /
- sizeof(struct pointcloud_vert);
- pcbuf->max = point_count;
- pcbuf->count = point_count;
- pcbuf->op = k_pointcloud_op_clear;
-
- vg_async_dispatch( call, async_pointcloud_sub );
- vg_async_call( pointcloud_async_end, NULL, 0 );
- }
- else{
- vg_async_call( pointcloud_clear_async, NULL, 0 );
- }
-}
-
-/*
- * Set new world to be loaded into portal
- */
-static void ent_portal_set_world( addon_reg *reg ){
- global_portal.display_world = reg;
- global_portal.dirty = 1;
-}
-
-/* VG Events */
-
-static void ent_portal_preupdate(void){
- if( global_portal.dirty && vg_loader_availible() ){
- global_portal.dirty = 0;
- vg_loader_start( ent_portal_pointcloud_load_thread, NULL );
- }
-}
-
-static void ent_portal_render(void){
- if( !global_portal.active )
- return;
-
- m4x3f mmdl;
-#if 0
- mdl_transform_m4x3( &mark_display->transform, mmdl );
- m4x3_rotate_y( mmdl, vg.time * 0.2 );
-#endif
- m3x3_identity( mmdl );
- m3x3_diagonal( mmdl, 20.0f );
- v3_copy( global_portal.display_co, mmdl[3] );
- mmdl[3][1] += 2.0f;
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE);
- glDisable(GL_DEPTH_TEST);
- pointcloud_render( &skaterift.cam, mmdl );
- glDisable(GL_BLEND);
- glEnable(GL_DEPTH_TEST);
-}
-
-#endif
+++ /dev/null
-#ifndef ENT_PORTAL_H
-#define ENT_PORTAL_H
-
-#include "addon.h"
-
-/* world portals */
-
-struct {
- addon_reg *display_world;
- int dirty, active;
-
- v3f display_co;
-}
-static global_portal = { .display_co = { 12,1,0 }, .active = 1 };
-
-#endif /* ENT_PORTAL_H */
#include "gameserver.h"
#include "highscores.c"
-#include "servermonitor_server.c"
#include "vg/vg_opt.h"
#include "network_common.h"
#include "gameserver_db.h"
return s / 0.01;
}
-static void test_runner( db_request *req ){
-#if 0
- vg_warn( "RUNNER\n" );
- char table[DB_TABLE_UID_MAX];
- if( db_get_highscore_table_name( "sr002-local-mp_mtzero",
- "Coastal Run", 0, table ) ){
- if( db_writeusertime( table, 76561198072130043, 232, 1 ) ){
- vg_success( "Written time\n" );
- i32 v = db_readusertime( table, 76561198072130043 );
- vg_success( "Returned time: %u\n", v );
- }
- }
-#endif
-}
-
-#define SIDELOAD
-#ifdef SIDELOAD
-#include "gameserver_sideload.h"
-static int bsideload = 0;
-const char *sideload_path = NULL;
-#endif
-
int main( int argc, char *argv[] ){
signal( SIGINT, inthandler );
signal( SIGQUIT, inthandler );
while( vg_argp( argc, argv ) ){
if( vg_long_opt( "noauth" ) )
gameserver.auth_mode = eServerModeNoAuthentication;
-
-#ifdef SIDELOAD
- if( (arg = vg_long_opt_arg( "sideload" )) ){
- sideload_path = arg;
- bsideload = 1;
- }
-#endif
}
vg_set_mem_quota( 80*1024*1024 );
vg_alloc_quota();
-
db_init();
- db_request *req = db_alloc_request(0);
- if( req ){
- req->handler = test_runner;
- db_send_request(req);
- }
-
-#ifdef SIDELOAD
- if( bsideload ){
- sideload( sideload_path );
- db_kill();
- db_free();
- return 0;
- }
-#endif
-
- monitor_start_server(); /* UNIX socket monitor */
/* steamworks init
* --------------------------------------------------------------- */
u64 server_ticks = 8000,
last_record_save = 8000,
- last_scoreboard_gen = 0,
- last_monitor_heartbeat = 0;
+ last_scoreboard_gen = 0;
while( !sig_stop ){
- monitor_event_loop();
steamworks_event_loop( hsteampipe );
poll_connections();
usleep(10000);
server_ticks ++;
- if( server_ticks >
- (last_monitor_heartbeat + seconds_to_server_ticks(10.0))){
- last_monitor_heartbeat = server_ticks;
- monitor_heartbeat();
- }
-
if( db_killed() )
break;
}
+++ /dev/null
-#include "gameserver.h"
-
-/* read entire binary file */
-static void *sl_file_read( const char *path, u32 *size ){
- FILE *f = fopen( path, "rb" );
- if( f ){
- void *buffer = malloc(0);
- u64 current = 0;
-
- /* read in chunks */
- for( u32 i=0; 1; i++ ){
- buffer = realloc( buffer, current+VG_FILE_IO_CHUNK_SIZE );
- u64 l = fread( buffer + current, 1, VG_FILE_IO_CHUNK_SIZE, f );
- current += l;
- if( l != VG_FILE_IO_CHUNK_SIZE ){
- if( feof( f ) ){
- break;
- }
- else{
- if( ferror( f ) ){
- fclose(f);
- vg_fatal_error( "read error" );
- }
- else{
- fclose(f);
- vg_fatal_error( "unknown error codition" );
- }
- }
- }
- }
-
- buffer = realloc( buffer, vg_align8(current) );
- fclose( f );
-
- *size = (u32)current;
- return buffer;
- }
- else{
- vg_error( "vg_disk_open_read: %s\n", strerror(errno) );
- return NULL;
- }
-}
-
-/* read entire file and append a null on the end */
-static char *sl_file_read_text( const char *path, u32 *sz ){
- u32 size;
- char *str = sl_file_read( path, &size );
-
- if( !str )
- return NULL;
-
- /* include null terminator */
- str = realloc( str, size+1 );
- str[ size ] = '\0';
- *sz = size+1;
-
- return str;
-}
-
-static void sideload( const char *folder ){
- char buf[ 4096 ];
- vg_str str;
- vg_strnull( &str, buf, 4096 );
- vg_strcat( &str, folder );
- vg_strcat( &str, "/users.csv" );
-
- u32 sz;
- char *data = sl_file_read_text( buf, &sz );
- char *_c = data, *lstart = NULL;
-
- while( *_c ){
- char c = *_c;
-
- if( lstart == NULL ){
- lstart = _c;
- }
-
- if( c == '\n' ){
- *_c = '\0';
- u64 steamid;
- char uname[48];
- sscanf( lstart, "%lu,%s", &steamid, uname );
- for( int i=0; i<48; i ++ ){
- if( uname[i] == '\0' ) break;
- if( uname[i] < ' ' || uname[i] > '~' ) uname[i] = '?';
- }
- lstart = NULL;
- db_updateuser( steamid, uname, 1 );
- }
-
- _c ++;
- }
-
- free( data );
-
- char *names[] = {
- "sr002-local-mp_mtzero:Megapark Green",
- "sr002-local-mp_mtzero:Megapark Blue",
- "sr002-local-mp_mtzero:Megapark Yellow",
- "sr002-local-mp_mtzero:Megapark Red",
- "sr002-local-mp_mtzero:Coastal Run",
- "sr002-local-mp_mtzero:Docks Jumps",
- };
-
- for( int i=0; i<6; i++ ){
- char fn[ 4096 ];
- sprintf( fn, "%s/00%d-track.csv", folder,i );
-
- data = sl_file_read_text( fn, &sz );
- _c = data, lstart = NULL;
-
- while( *_c ){
- char c = *_c;
-
- if( lstart == NULL ){
- lstart = _c;
- }
-
- if( c == '\n' ){
- *_c = '\0';
- int id, s0, score;
- u64 steamid;
-
- sscanf( lstart, "%d,%d,%d,%lu", &id, &s0, &score, &steamid );
- lstart = NULL;
- db_writeusertime( names[i], steamid, score, 1 );
- }
-
- _c ++;
- }
-
- free( data );
-
- }
-}
+++ /dev/null
-#ifndef MONITORINFO_H
-#define MONITORINFO_H
-
-static const char *MONITOR_SOCK_PATH = "\0skaterift.server_monitor";
-
-#endif /* MONITORINFO_H */
+++ /dev/null
-#if 0
-//#ifndef POINTCLOUD_H
-#define POINTCLOUD_H
-
-#include "common.h"
-#include "world.h"
-#include "shaders/point_map.h"
-
-#define POINTCLOUD_POINTS 250000
-
-struct pointcloud{
- GLuint vao, vbo;
- u32 count;
-
- f64 anim_start;
- f32 visibility;
- enum pointcloud_anim{
- k_pointcloud_anim_opening,
- k_pointcloud_anim_hiding,
- k_pointcloud_anim_idle_any,
- k_pointcloud_anim_idle_open,
- k_pointcloud_anim_idle_closed,
- }
- anim;
-}
-static pointcloud;
-
-#pragma pack(push,1)
-struct pointcloud_vert{
- i16 pos[4]; /* float[ -1 -> 1 ] */
- u8 colour[4]; /* float[ 0 -> 1 ] */
-};
-#pragma pack(pop)
-
-typedef struct pointcloud_vert pointcloud_vert;
-typedef struct pointcloud_buffer pointcloud_buffer;
-
-struct pointcloud_buffer{
- u32 max, count;
- boxf boundary;
-
- enum pointcloud_op{
- k_pointcloud_op_clear,
- k_pointcloud_op_append
- }
- op;
- pointcloud_vert buf[];
-};
-
-static void async_pointcloud_sub( void *payload, u32 size ){
- glBindVertexArray( pointcloud.vao );
- glBindBuffer( GL_ARRAY_BUFFER, pointcloud.vbo );
-
- pointcloud_buffer *buf = payload;
-
- u32 start,end,count;
- if( buf->op == k_pointcloud_op_append ){
- start = pointcloud.count;
- end = pointcloud.count + buf->count;
- }
- else{
- start = 0;
- end = buf->count;
- }
-
- end = VG_MIN(POINTCLOUD_POINTS,end);
- count = end-start;
-
- if( count ){
- u32 size = count * sizeof(pointcloud_vert),
- offset = start * sizeof(pointcloud_vert);
-
- glBufferSubData( GL_ARRAY_BUFFER, offset, size, buf->buf );
- pointcloud.count = end;
- }
-}
-
-static void async_pointcloud_alloc( void *payload, u32 size ){
- glGenVertexArrays( 1, &pointcloud.vao );
- glGenBuffers( 1, &pointcloud.vbo );
- glBindVertexArray( pointcloud.vao );
-
- size_t stride = sizeof( pointcloud_vert );
-
- glBindBuffer( GL_ARRAY_BUFFER, pointcloud.vbo );
- glBufferData( GL_ARRAY_BUFFER, stride * POINTCLOUD_POINTS,
- NULL, GL_DYNAMIC_DRAW );
-
- /* 0: coordinates */
- glVertexAttribPointer( 0, 4, GL_SHORT, GL_TRUE, stride, (void*)0 );
- glEnableVertexAttribArray( 0 );
-
- /* 1: colour */
- glVertexAttribPointer( 1, 4, GL_UNSIGNED_BYTE, GL_TRUE,
- stride, (void *)offsetof(pointcloud_vert, colour) );
- glEnableVertexAttribArray( 1 );
- VG_CHECK_GL_ERR();
-}
-
-static void pointcloud_init(void){
- vg_async_call( async_pointcloud_alloc, NULL, 0 );
- shader_point_map_register();
-}
-
-static void pointcloud_animate( enum pointcloud_anim anim ){
- pointcloud.anim = anim;
- pointcloud.anim_start = vg.time;
-}
-
-static int pointcloud_idle(void){
- if( pointcloud.anim >= k_pointcloud_anim_idle_any ) return 1;
- else return 0;
-}
-
-static void pointcloud_render( camera *cam, m4x3f model ){
- if( pointcloud.anim < k_pointcloud_anim_idle_any ){
- f32 const k_transition = 0.6f;
- f32 t = (vg.time - pointcloud.anim_start) / k_transition;
-
- if( pointcloud.anim == k_pointcloud_anim_hiding ){
- if( t > 1.0f ){
- pointcloud.visibility = 0.0f;
- pointcloud.anim = k_pointcloud_anim_idle_closed;
- }
- else pointcloud.visibility = 1.0f-t;
- }
- else if( pointcloud.anim == k_pointcloud_anim_opening ){
- if( t > 1.0f ){
- pointcloud.visibility = 1.0f;
- pointcloud.anim = k_pointcloud_anim_idle_open;
- }
- else pointcloud.visibility = t;
- }
- }
-
- if( pointcloud.visibility == 0.0f ) return;
-
- m4x4f upvmprev;
- m4x3_expand( model, upvmprev );
- m4x4_mul( cam->mtx_prev.pv, upvmprev, upvmprev );
-
- shader_point_map_use();
- shader_point_map_uPv( cam->mtx.pv );
- shader_point_map_uPvmPrev( upvmprev );
- shader_point_map_uMdl( model );
- shader_point_map_uCamera( cam->pos );
- shader_point_map_uAnim( (v4f){ 32, 1.0f-pointcloud.visibility,
- 0.0f, vg.time } );
-
- glBindVertexArray( pointcloud.vao );
- glEnable( GL_PROGRAM_POINT_SIZE );
- glDrawArrays( GL_POINTS, 0, pointcloud.count );
-}
-
-static void pointcloud_packvert( pointcloud_vert *vert, v3f pos, v4f colour ){
- for( u32 i=0; i<3; i++ )
- vert->pos[i] = (pos[i]-0.5f) * 32767.0f;
-
- for( u32 i=0; i<4; i++ )
- vert->colour[i] = colour[i] * 255.0f;
-}
-
-static void pointcloud_async_end(void *_, u32 __){
- pointcloud_animate( k_pointcloud_anim_opening );
-}
-
-static void pointcloud_clear_async(void *_, u32 __){
- pointcloud.count = 0;
- pointcloud_animate( k_pointcloud_anim_opening );
-}
-
-#endif /* POINTCLOUD_H */
+++ /dev/null
-/*
- * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
- */
-
-/*
- * This server application requires steamclient.so to be present in the
- * executable directory. This is not provided by vg system, it must be
- * downloaded via steamcmd. It will likely be somewhere in ~/.steam/ ...
- */
-
-#define _DEFAULT_SOURCE
-#include <unistd.h>
-#include <signal.h>
-#include <time.h>
-
-volatile sig_atomic_t sig_stop;
-
-static void inthandler( int signum ) {
- sig_stop = 1;
-}
-
-#define VG_SERVER
-#include "vg/vg.h"
-#include "vg/vg_steam.h"
-#include "vg/vg_steam_networking.h"
-#include "vg/vg_steam_http.h"
-#include "vg/vg_steam_auth.h"
-#include "network_msg.h"
-#include "highscores.h"
-
-/* implementation */
-#include "highscores.c"
-
-static const u64 k_connection_unauthorized = 0xffffffffffffffff;
-
-static void *hSteamHTTP,
- *hSteamNetworkingSockets;
-
-static u8 steam_symetric_key[ k_nSteamEncryptedAppTicketSymmetricKeyLen ];
-static HSteamNetPollGroup client_pollgroup;
-
-#if 0
-static void recieve_http( void *callresult, void *context )
-{
- HTTPRequestCompleted_t *result = callresult;
-
- HTTPRequestHandle request = result->m_hRequest;
- u32 size = 0;
-
- SteamAPI_ISteamHTTP_GetHTTPResponseBodySize( hSteamHTTP, request, &size );
-
- u8 *buffer = vg_alloc( size );
- SteamAPI_ISteamHTTP_GetHTTPResponseBodyData(
- hSteamHTTP, request, buffer, size );
-
- buffer[size-1] = '\0';
- vg_info( "%s\n", (char *)buffer );
-
- vg_free( buffer );
- SteamAPI_ISteamHTTP_ReleaseHTTPRequest( hSteamHTTP, result->m_hRequest );
-}
-#endif
-
-static u64_steamid get_connection_authsteamid( SteamNetworkingMessage_t *msg )
-{
- i64 userdata = SteamAPI_ISteamNetworkingSockets_GetConnectionUserData(
- hSteamNetworkingSockets, msg->m_conn );
-
- return *((u64_steamid *)&userdata);
-}
-
-static void set_connection_authsteamid(HSteamNetConnection con, u64_steamid id)
-{
- i64 userdata = *((i64 *)&id);
-
- SteamAPI_ISteamNetworkingSockets_SetConnectionUserData(
- hSteamNetworkingSockets, con, userdata );
-}
-
-static void new_client_connecting( HSteamNetConnection client )
-{
- EResult accept_status = SteamAPI_ISteamNetworkingSockets_AcceptConnection(
- hSteamNetworkingSockets, client );
-
- if( accept_status == k_EResultOK )
- {
- vg_success( "Accepted client (id: %u)\n", client );
- SteamAPI_ISteamNetworkingSockets_SetConnectionPollGroup(
- hSteamNetworkingSockets,
- client, client_pollgroup );
-
- /* Just to be sure */
- set_connection_authsteamid( client, -1 );
- }
- else
- {
- vg_warn( "Error accepting client (id: %u)\n", client );
- }
-}
-
-static void on_auth_status( CallbackMsg_t *msg )
-{
- SteamNetAuthenticationStatus_t *info = (void *)msg->m_pubParam;
- vg_info( " Authentication availibility: %s\n",
- string_ESteamNetworkingAvailability(info->m_eAvail) );
- vg_info( " %s\n", info->m_debugMsg );
-}
-
-static void on_connect_status( CallbackMsg_t *msg )
-{
- SteamNetConnectionStatusChangedCallback_t *info = (void *)msg->m_pubParam;
- vg_info( " Connection status changed for %lu\n", info->m_hConn );
-
- vg_info( " %s -> %s\n",
- string_ESteamNetworkingConnectionState(info->m_eOldState),
- string_ESteamNetworkingConnectionState(info->m_info.m_eState) );
-
- if( info->m_info.m_eState==k_ESteamNetworkingConnectionState_Connecting )
- {
- new_client_connecting( info->m_hConn );
- }
-}
-
-static void on_inet_auth( SteamNetworkingMessage_t *msg )
-{
- if( get_connection_authsteamid( msg ) != k_connection_unauthorized )
- {
- vg_warn( "Already authorized this user but app ticket was sent"
- " again (%u)\n", msg->m_conn );
- return;
- }
-
- vg_low( "Attempting to verify user\n" );
-
- if( msg->m_cbSize < sizeof(netmsg_auth) )
- {
- vg_error( "Malformed auth ticket, too small (%u)\n", msg->m_conn );
- return;
- }
-
- netmsg_auth *auth = msg->m_pData;
-
- if( msg->m_cbSize < sizeof(netmsg_auth)+auth->ticket_length ||
- auth->ticket_length > 1024 )
- {
- vg_error( "Malformed auth ticket, ticket_length incorrect (%u)\n",
- auth->ticket_length );
- return;
- }
-
- u8 decrypted[1024];
- u32 ticket_len = 1024;
-
- int success = SteamEncryptedAppTicket_BDecryptTicket(
- auth->ticket, auth->ticket_length, decrypted,
- &ticket_len, steam_symetric_key,
- k_nSteamEncryptedAppTicketSymmetricKeyLen );
-
- if( !success )
- {
- vg_error( "Failed to decrypt users ticket (client %u)\n", msg->m_conn );
- vg_error( " ticket length: %u\n", auth->ticket_length );
-
- SteamAPI_ISteamNetworkingSockets_CloseConnection(
- hSteamNetworkingSockets,
- msg->m_conn, 0, NULL, 1 );
- return;
- }
-
- if( SteamEncryptedAppTicket_GetTicketIssueTime( decrypted, ticket_len ))
- {
- RTime32 ctime = time(NULL),
- tickettime = SteamEncryptedAppTicket_GetTicketIssueTime(
- decrypted, ticket_len ),
- expiretime = tickettime + 24*3*60*60;
-
- if( ctime > expiretime )
- {
- vg_error( "Ticket expired (client %u)\n", msg->m_conn );
-
- /* TODO: Send expired information */
- SteamAPI_ISteamNetworkingSockets_CloseConnection(
- hSteamNetworkingSockets,
- msg->m_conn, 0, NULL, 1 );
- return;
- }
- }
-
- CSteamID steamid;
- SteamEncryptedAppTicket_GetTicketSteamID( decrypted, ticket_len, &steamid );
- vg_success( "User is authenticated! steamid %lu (%u)\n",
- steamid.m_unAll64Bits, msg->m_conn );
-
- set_connection_authsteamid( msg->m_conn, steamid.m_unAll64Bits );
-}
-
-static int inet_require_auth( SteamNetworkingMessage_t *msg )
-{
- if( get_connection_authsteamid( msg ) == k_connection_unauthorized )
- {
- vg_warn( "Unauthorized request! Disconnecting client: %u\n",
- msg->m_conn );
-
- SteamAPI_ISteamNetworkingSockets_CloseConnection(
- hSteamNetworkingSockets,
- msg->m_conn, 0, NULL, 1 );
-
- return 0;
- }
- else return 1;
-}
-
-static void on_inet_score_request( SteamNetworkingMessage_t *msg )
-{
- if( !inet_require_auth(msg) ) return;
-
- SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
- hSteamNetworkingSockets, msg->m_conn,
- &scoreboard_client_data, sizeof(netmsg_scoreboard),
- k_nSteamNetworkingSend_Reliable, NULL );
-}
-
-static void on_inet_set_nickname( SteamNetworkingMessage_t *msg )
-{
- if(!inet_require_auth(msg)) return;
-
- u64_steamid steamid = get_connection_authsteamid(msg);
- netmsg_set_nickname *setnick = msg->m_pData;
- if( msg->m_cbSize < sizeof(netmsg_set_nickname) )
- {
- vg_warn( "Invalid nickname request from client: %u, steamid: %lu\n",
- msg->m_conn, steamid );
- return;
- }
-
- highscore_set_user_nickname( steamid, setnick->nickname );
-}
-
-static void on_inet_set_score( SteamNetworkingMessage_t *msg )
-{
- if(!inet_require_auth(msg)) return;
-
- u64_steamid steamid = get_connection_authsteamid(msg);
-
- if( msg->m_cbSize < sizeof(netmsg_set_score) )
- {
- vg_warn( "Invalid set score post from client: %u, steamid: %lu\n",
- msg->m_conn, steamid );
- return;
- }
-
- netmsg_set_score *info = msg->m_pData;
-
- if( msg->m_cbSize < sizeof(netmsg_set_score) +
- sizeof(struct netmsg_score_record)*info->record_count )
- {
- vg_warn( "Malformed set score post from client: %u, steamid: %lu\n",
- msg->m_conn, steamid );
- return;
- }
-
- for( int i=0; i<info->record_count; i++ )
- {
- highscore_record temp;
- temp.trackid = info->records[i].trackid;
- temp.datetime = time(NULL);
- temp.playerid = steamid;
- temp.points = info->records[i].points;
- temp.time = info->records[i].time;
-
- highscores_push_record( &temp );
- }
-}
-
-static void poll_connections(void)
-{
- SteamNetworkingMessage_t *messages[32];
- int len;
-
- while(1){
- len = SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnPollGroup(
- hSteamNetworkingSockets,
- client_pollgroup, messages, vg_list_size(messages) );
-
- if( len <= 0 )
- return;
-
- for( int i=0; i<len; i++ ){
- SteamNetworkingMessage_t *msg = messages[i];
-
- if( msg->m_cbSize < sizeof(netmsg_blank) ){
- vg_warn( "Discarding message (too small: %d)\n",
- msg->m_cbSize );
- continue;
- }
-
- netmsg_blank *tmp = msg->m_pData;
-
- if( tmp->inetmsg_id == k_inetmsg_auth )
- on_inet_auth( msg );
- else if( tmp->inetmsg_id == k_inetmsg_scores_request )
- on_inet_score_request( msg );
- else if( tmp->inetmsg_id == k_inetmsg_set_nickname )
- on_inet_set_nickname( msg );
- else if( tmp->inetmsg_id == k_inetmsg_set_score )
- on_inet_set_score( msg );
- else {
- vg_warn( "Unknown inetmsg_id recieved from client. (%u)\n",
- tmp->inetmsg_id );
- }
-
- SteamAPI_SteamNetworkingMessage_t_Release( msg );
- }
- }
-}
-
-static u64 seconds_to_server_ticks( double s )
-{
- return s / 0.1;
-}
-
-static void generate_boards(void)
-{
- FILE *fp = fopen( "www/html/srhighscores.txt", "w" );
-
- for( int i=0; i<vg_list_size(track_infos); i++ ){
- struct netmsg_board *board = &scoreboard_client_data.boards[i];
-
- highscores_board_generate( board->data, i, 10 );
- highscores_board_printf( fp, board->data, 10 );
- }
-
- fclose( fp );
-}
-
-int main( int argc, char *argv[] )
-{
- signal( SIGINT, inthandler );
- signal( SIGQUIT, inthandler );
-
- /* TODO: Options to override, ammend, remove etc */
-
- vg_set_mem_quota( 80*1024*1024 );
- vg_alloc_quota();
-
- highscores_init( 250000, 10000 );
-
- if( !highscores_read() )
- highscores_create_db();
-
- steamworks_ensure_txt( "2103940" );
- if( !vg_load_steam_symetric_key( "application_key", steam_symetric_key ) )
- return 0;
-
- if( !SteamGameServer_Init( 0, 27400, 27401, eServerModeAuthentication,
- "1.0.0.0" ) )
- {
- vg_error( "SteamGameServer_Init failed\n" );
- return 0;
- }
-
- void *hSteamGameServer = SteamAPI_SteamGameServer();
- SteamAPI_ISteamGameServer_LogOnAnonymous( hSteamGameServer );
-
- SteamAPI_ManualDispatch_Init();
- HSteamPipe hsteampipe = SteamGameServer_GetHSteamPipe();
-
- //hSteamHTTP = SteamAPI_SteamGameServerHTTP();
- hSteamNetworkingSockets =
- SteamAPI_SteamGameServerNetworkingSockets_SteamAPI();
-
- /*
- * Server code
- */
-
- steam_register_callback( k_iSteamNetAuthenticationStatus, on_auth_status );
- steam_register_callback( k_iSteamNetConnectionStatusChangedCallBack,
- on_connect_status );
-
- vg_success( "Steamworks API running\n" );
- steamworks_event_loop( hsteampipe );
-
- /*
- * Create a listener
- */
-
- HSteamListenSocket listener;
- SteamNetworkingIPAddr localAddr;
- SteamAPI_SteamNetworkingIPAddr_Clear( &localAddr );
- localAddr.m_port = 27402;
-
- listener = SteamAPI_ISteamNetworkingSockets_CreateListenSocketIP(
- hSteamNetworkingSockets, &localAddr, 0, NULL );
- client_pollgroup = SteamAPI_ISteamNetworkingSockets_CreatePollGroup(
- hSteamNetworkingSockets );
-
- u64 server_ticks = 8000,
- last_record_save = 8000,
- last_scoreboard_gen = 0;
-
- generate_boards();
-
- while( !sig_stop )
- {
- steamworks_event_loop( hsteampipe );
- poll_connections();
-
- usleep(100000);
- server_ticks ++;
-
- if(server_ticks > last_scoreboard_gen + seconds_to_server_ticks(1.0*60.0))
- {
- last_scoreboard_gen = server_ticks;
- generate_boards();
- }
-
- if(server_ticks > last_record_save + seconds_to_server_ticks( 10.0*60.0 ))
- {
- last_record_save = server_ticks;
- highscores_serialize_all();
- }
- }
-
- highscores_serialize_all();
-
- SteamAPI_ISteamNetworkingSockets_DestroyPollGroup( hSteamNetworkingSockets,
- client_pollgroup );
- SteamAPI_ISteamNetworkingSockets_CloseListenSocket(
- hSteamNetworkingSockets, listener );
-
- vg_info( "Shutting down\n..." );
- SteamGameServer_Shutdown();
-
- return 0;
-}
+++ /dev/null
-#ifndef SERVERMONITOR_H
-#define SERVERMONITOR_H
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-#ifndef VG_RELEASE
- #define VG_DEVWINDOW
-#endif
-
-#define VG_3D
-#define VG_GAME
-#define VG_MSG_V1_SUPPORT
-#define VG_LOG_SOURCE_INFO
-#define VG_TIMESTEP_FIXED (1.0/60.0)
-#define VG_NO_STEAM
-#define VG_NO_AUDIO
-#include "vg/vg.h"
-#include "vg/vg_lines.h"
-#include "vg/vg_imgui.h"
-#include "monitorinfo.h"
-
-int main( int argc, char *argv[] ){
- vg_mem.use_libc_malloc = 0;
- vg_set_mem_quota( 160*1024*1024 );
- vg_enter( argc, argv, "Server Monitor" );
- return 0;
-}
-
-static void vg_launch_opt(void){}
-
-static int sockfd = -1;
-
-static void connect_to_monitor_server(void){
- struct sockaddr_un serv_addr;
-
- if((sockfd = socket(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0)) < 0){
- vg_error("Could not create socket\n");
- sockfd = -1;
- return;
- }
-
- memset( &serv_addr, 0, sizeof(serv_addr) );
-
- serv_addr.sun_family = AF_UNIX;
- strcpy( serv_addr.sun_path, MONITOR_SOCK_PATH );
-
- vg_info( "Connecting...\n" );
- if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0 ){
- vg_error("Connect Failed \n");
- close( sockfd );
- sockfd = -1;
- return;
- }
-
- vg_success( "Connected\n" );
-}
-
-static void vg_preload(void){}
-
-static void vg_load(void){
- vg_bake_shaders();
- vg_console_load_autos();
-}
-
-/*
- * UPDATE LOOP
- * ---------------------------------------------------------------------------*/
-
-static void vg_pre_update(void){
- if( sockfd == -1 ) return;
-
- char recvBuff[1024];
- int len = read(sockfd, recvBuff, sizeof(recvBuff)-1);
-
- if( len > 0 ){
- recvBuff[ len ] = 0;
- vg_info( "%s", recvBuff );
- }
-}
-
-static void vg_fixed_update(void){
-}
-
-static void vg_post_update(void){
-}
-
-/*
- * RENDERING
- * ---------------------------------------------------------------------------*/
-
-static void vg_framebuffer_resize( int w, int h ){
-}
-
-static void vg_render(void){
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
- glViewport( 0,0, vg.window_x, vg.window_y );
- glDisable( GL_DEPTH_TEST );
- glDisable( GL_BLEND );
-
- glClearColor( 0.1f, 0.1f, 0.1f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
-
- vg_lines_drawall();
-}
-
-static void vg_gui(void){
- vg_ui.wants_mouse = 1;
- static i32 page = 0;
- ui_rect panel = { 0, 0, vg.window_x, vg.window_y };
- ui_rect_pad( panel, (ui_px[]){ 8, 8 } );
-
- const char *pages[] = { "Status", "Options" };
- ui_tabs( panel, panel, pages, vg_list_size(pages), &page );
-
- if( page == 0 ){
- char buf[512];
- snprintf( buf, 511, "%sSockfd: %d", (sockfd==-1?KRED:KGRN), sockfd );
- ui_info( panel, buf );
-
- if( sockfd == -1 ){
- if( ui_button( panel, "Reconnect" ) == 1 ){
- connect_to_monitor_server();
- }
- }
- else{
- if( ui_button( panel, "Disconnect" ) == 1 ){
- close( sockfd );
- sockfd = -1;
- }
- }
- }
-}
-
-#endif /* SERVERMONITOR_H */
+++ /dev/null
-#include <sys/socket.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include "monitorinfo.h"
-#include "gameserver.h"
-
-static int monitor_write_index( int index, const void *buf, size_t nbyte ){
- int fd = gameserver.monitor_clients[ index ];
- if( write( fd, buf, nbyte ) == -1 ){
- gameserver.monitor_clients[ index ] = -1;
- vg_error( "Monitor client disconnected (%d)\n", index );
- close( fd );
- return 0;
- }
- else
- return 1;
-}
-
-static void monitor_accept_connections(void){
- char sendbuff[1025];
- int fd = accept( gameserver.monitor_fd, (struct sockaddr*)NULL, NULL );
-
- if( fd == -1 )
- return;
-
- int index = -1;
- for( int i=0; i<vg_list_size(gameserver.monitor_clients); i ++ ){
- if( gameserver.monitor_clients[i] == -1 ){
- index = i;
- break;
- }
- }
-
- vg_info( "New monitor client (fd: %d, index: %d)\n", fd, index );
-
- if( index == -1 ){
- snprintf( sendbuff, sizeof(sendbuff), "MONITOR_FULL\n" );
- write( fd, sendbuff, strlen(sendbuff) );
- close( fd );
- return;
- }
-
- gameserver.monitor_clients[ index ] = fd;
-
- time_t ticks = time( NULL );
- snprintf( sendbuff, sizeof(sendbuff), "logged in %.24s\n", ctime(&ticks) );
- if( monitor_write_index( index, sendbuff, strlen(sendbuff) ) )
- vg_success( "Accepted\n" );
-}
-
-static void monitor_heartbeat(void){
- for( int i=0; i<vg_list_size(gameserver.monitor_clients); i++ ){
- if( gameserver.monitor_clients[i] != -1 )
- monitor_write_index( i, NULL, 0 );
- }
-}
-
-static void monitor_start_server(void){
- for( int i=0; i<vg_list_size(gameserver.monitor_clients); i++ ){
- gameserver.monitor_clients[i] = -1;
- }
-
- struct sockaddr_un serv_addr;
-
- char sendbuff[1025];
-
- gameserver.monitor_fd = socket( AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0 );
- memset( &serv_addr, 0, sizeof(serv_addr) );
- memset( sendbuff, 0, sizeof(sendbuff) );
-
- serv_addr.sun_family = AF_UNIX;
- strcpy( serv_addr.sun_path, MONITOR_SOCK_PATH );
-
- unlink( MONITOR_SOCK_PATH );
- bind( gameserver.monitor_fd,
- (struct sockaddr*)&serv_addr, sizeof(serv_addr) );
- listen( gameserver.monitor_fd, 4 );
-}
-
-static void monitor_event_loop(void){
- monitor_accept_connections();
-}
+++ /dev/null
-/*
- * =============================================================================
- *
- * Copyright . . . -----, ,----- ,---. .---.
- * 2021-2023 |\ /| | / | | | | /|
- * | \ / | +-- / +----- +---' | / |
- * | \ / | | / | | \ | / |
- * | \/ | | / | | \ | / |
- * ' ' '--' [] '----- '----- ' ' '---' SOFTWARE
- *
- * =============================================================================
- */
-
-#define SR_NETWORKED
-#define VG_DEVWINDOW
-
-#define SKATERIFT_APPID 2103940
-
-#define VG_TIMESTEP_FIXED (1.0/60.0)
-#define VG_3D
-#define VG_GAME
-#define VG_MSG_V1_SUPPORT
-#define VG_LOG_SOURCE_INFO
-#include "vg/vg.h"
-
-static int skaterift_loaded = 0;
-static char g_an_buffer[ 96 ],
- g_an_buffer2[ 96 ];
-
-int main( int argc, char *argv[] ){
- vg_mem.use_libc_malloc = 0;
- vg_set_mem_quota( 160*1024*1024 );
- vg_enter( argc, argv, "Voyager Game Engine" );
- return 0;
-}
-
-static void vg_launch_opt(void){
-}
-
-static void vg_preload(void){
-vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" );
-vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" );
-vg_info(" | \\ / | +-- / +----- +---' | / | \n" );
-vg_info(" | \\ / | | / | | \\ | / | \n" );
-vg_info(" | \\/ | | / | | \\ | / | \n" );
-vg_info(" ' ' '--' [] '----- '----- ' ' '---' "
- "SOFTWARE\n" );
-}
-
-static void skaterift_load_post( void *data, u32 len ){
- skaterift_loaded = 1;
-}
-
-static void vg_load(void){
- vg_bake_shaders();
- vg_async_call( skaterift_load_post, NULL, 0 );
-}
-
-static void vg_pre_update(void){
-}
-
-static void vg_fixed_update(void){
-}
-
-static void vg_post_update(void){
-}
-
-static void vg_framebuffer_resize( int w, int h ){
- //render_fb_resize();
-}
-
-static void vg_render(void){
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
-
- glViewport( 0,0, vg.window_x, vg.window_y );
- glDisable( GL_DEPTH_TEST );
-
- glClearColor( 0.0f, 0.2f, 0.7f, 0.0f );
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
-
- /* Other shite */
- glDisable( GL_BLEND );
- glDisable( GL_DEPTH_TEST );
- vg_lines_drawall();
-}
-
-static struct ui_enum_opt dropdown_options[] = {
- { 0, "Zero" },
- { 3, "Three" },
- { -1, "Minus One" }
-};
-static i32 dropdown_value = 8;
-static i32 checkbox_value = 0;
-
-static void vg_gui(void){
- if( !skaterift_loaded ) return;
-
- static ui_rect window;
- static int once = 1;
- if( once ){
- ui_rect screen = { 0, 0, vg.window_x, vg.window_y };
- rect_copy( (ui_rect){ 0, 0, 1000, 700 }, window );
- ui_rect_center( screen, window );
- once = 0;
- }
-
- vg_ui.wants_mouse = 1;
-
- ui_rect panel, content;
- ui_panel( window, panel );
-
- static i32 page = 0;
- ui_tabs( panel, content,
- (const char *[]){ "Controls", "Other", "Nothing" }, 3, &page );
-
- if( page == 0 ){
- ui_enum( content, "Select enum:", dropdown_options, 3, &dropdown_value );
- ui_checkbox( content, "Toggly:", &checkbox_value );
- ui_textbox( content, "Single:", g_an_buffer, 96, 1, 0, NULL );
- ui_textbox( content, "Multi:", g_an_buffer2, 96, 5, 0, NULL );
-
- if( ui_button( content, "Hello" ) == 1 ){
- vg_success( "Ding!\n" );
- }
- }
- else if( page == 1 ){
- if( ui_button( content, "Another button" ) == 1 ){
- vg_error( "Press\n" );
- }
- }
-
-
-#if 0
- ui_fill( window, ui_colour( k_ui_bg+1 ) );
- ui_outline( window, 1, ui_colour( k_ui_bg+7 ) );
-
- ui_rect title, panel;
- ui_split( window, k_ui_axis_h, 28, 0, title, panel );
- ui_fill( title, ui_colour( k_ui_bg+7 ) );
- ui_text( title, "Workshop tool", 1, k_ui_align_middle_center,
- ui_colourcont(k_ui_bg+7) );
-
- ui_rect quit_button;
- ui_split( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button );
- if( ui_button_text( quit_button, "x", 1 ) == 1 ){
- ui_start_modal( g_an_buffer, UI_MODAL_GOOD );
- }
-
- ui_rect tbox;
- ui_split( panel, k_ui_axis_h, 28, 0, tbox, panel );
- ui_textbox( tbox, g_an_buffer, 4096, 0, NULL );
-
- ui_dev_colourview();
-#endif
-}
+++ /dev/null
-#
-# Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
-#
-
-vg_src="main.c"
-vg_target="game"
-
-shader blit blit.vs blit.fs
-shader fscolour blit.vs colour.fs
-shader terrain standard.vs terrain.fs
-shader vblend standard.vs vblend.fs
-shader alphatest standard.vs std_alphatest.fs
-shader standard standard.vs standard.fs
-shader unlit standard.vs unlit.fs
-shader character character.vs character.fs
-shader gate gate.vs gate.fs
-shader gatelq gate.vs gate_lq.fs
-shader water standard.vs water.fs
-shader sky standard.vs sky.fs
-shader planeinf standard.vs planeinf.fs
-shader gpos standard.vs gpos.fs
-shader route standard.vs route.fs
-shader scoretext scoretext.vs vblend.fs