#include "ent_region.h"
#include "gui.h"
+#include "network_common.h"
+#include "network.h"
+
+static u32 region_spark_colour( u32 flags ){
+ if( flags & k_ent_route_flag_achieve_gold )
+ return 0xff8ce0fa;
+ else if( flags & k_ent_route_flag_achieve_silver )
+ return 0xffc2c2c2;
+ else
+ return 0x00;
+}
static void ent_region_call( world_instance *world, ent_call *call ){
ent_region *region =
gui_location_print_ccmd( 1, (const char *[]){
mdl_pstr(&world->meta,region->pstr_title)} );
- if( region->flags & k_ent_route_flag_achieve_gold )
- localplayer.effect_data.spark.colour = 0xff8ce0fa;
- else if( region->flags & k_ent_route_flag_achieve_silver )
- localplayer.effect_data.spark.colour = 0xffc2c2c2;
- else
- localplayer.effect_data.spark.colour = 0x00;
+ vg_strncpy( mdl_pstr(&world->meta,region->pstr_title),
+ global_ent_region.location, NETWORK_REGION_MAX,
+ k_strncpy_always_add_null );
+ global_ent_region.flags = region->flags;
+ network_send_region();
+
+ localplayer.effect_data.spark.colour = region_spark_colour(region->flags);
}
else if( call->function == 1 ){ /* leave */
for( u32 i=0; i<mdl_arrcount(&world->ent_route); i ++ ){
#include "world_entity.h"
+struct {
+ char location[ NETWORK_REGION_MAX ];
+ u32 flags;
+}
+static global_ent_region;
+
+static u32 region_spark_colour( u32 flags );
+
#endif /* ENT_REGION_H */
k_ent_route_flag_achieve_silver = 0x1,
k_ent_route_flag_achieve_gold = 0x2,
- k_ent_route_flag_out_of_zone = 0x10
+ k_ent_route_flag_out_of_zone = 0x10,
+ k_ent_region_flag_hasname = 0x20
};
struct ent_route{
alloca( sizeof(netmsg_playeritem) + ADDON_UID_MAX );
item->inetmsg_id = k_inetmsg_playeritem;
+ netmsg_region *region = alloca( sizeof(netmsg_region) + NETWORK_REGION_MAX );
+ region->inetmsg_id = k_inetmsg_region;
+
for( int i=0; i<vg_list_size(gameserver.clients); i++ ){
struct gameserver_client *client = &gameserver.clients[i];
gameserver_send_to_client( index, item, size,
k_nSteamNetworkingSend_Reliable );
}
+
+ /* region */
+
+ region->client = i;
+ region->flags = client->region_flags;
+ u32 l = vg_strncpy( client->region, region->loc, NETWORK_REGION_MAX,
+ k_strncpy_always_add_null );
+ size = sizeof(netmsg_region) + l + 1;
+
+ gameserver_send_to_client( index, region, size,
+ k_nSteamNetworkingSend_Reliable );
}
}
gameserver_send_to_all( client_id, prop, sizeof(netmsg_chat)+l+1,
k_nSteamNetworkingSend_Reliable );
}
+ else if( tmp->inetmsg_id == k_inetmsg_region ){
+ netmsg_region *region = msg->m_pData,
+ *prop = alloca( sizeof(netmsg_region) + NETWORK_REGION_MAX );
+
+ prop->inetmsg_id = k_inetmsg_region;
+ prop->client = client_id;
+ prop->flags = region->flags;
+
+ u32 l = network_msgstring(
+ region->loc, msg->m_cbSize, sizeof(netmsg_region),
+ client->region, NETWORK_REGION_MAX );
+ client->region_flags = region->flags;
+
+ l = vg_strncpy( client->region, prop->loc, NETWORK_REGION_MAX,
+ k_strncpy_always_add_null );
+
+ gameserver_send_to_all( client_id, prop, sizeof(netmsg_region)+l+1,
+ k_nSteamNetworkingSend_Reliable );
+ vg_info( "client %d moved to region: %s\n", client_id, client->region );
+ }
else {
vg_warn( "Unknown inetmsg_id recieved from client. (%u)\n",
tmp->inetmsg_id );
}
items[k_netmsg_playeritem_max];
+ char region[ NETWORK_REGION_MAX ];
+ u32 region_flags;
+
u64 steamid;
}
clients[ NETWORK_MAX_PLAYERS ];
#include "world_sfd.h"
#include "world_routes.h"
#include "vg/vg_imgui.h"
+#include "gui.h"
+#include "ent_region.h"
static void scores_update(void);
k_nSteamNetworkingSend_Reliable, NULL );
}
+static void network_send_region(void){
+ if( !network_connected() )
+ return;
+
+ netmsg_region *region = alloca( sizeof(netmsg_region) + NETWORK_REGION_MAX );
+
+ region->inetmsg_id = k_inetmsg_region;
+ region->client = 0;
+ region->flags = global_ent_region.flags;
+
+ u32 l = vg_strncpy( global_ent_region.location, region->loc,
+ NETWORK_REGION_MAX, k_strncpy_always_add_null );
+
+ SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
+ hSteamNetworkingSockets, network_client.remote,
+ region, sizeof(netmsg_region)+l+1,
+ k_nSteamNetworkingSend_Reliable, NULL );
+}
+
static void network_send_request( netmsg_request *req, vg_msg *body,
void (*callback)(
netmsg_request *res, vg_msg *body,
for( u32 i=0; i<k_netmsg_playeritem_max; i ++ ){
network_send_item(i);
}
+ network_send_region();
}
static void poll_remote_connection(void){
static void chat_send_message( const char *message );
static void render_server_status_gui(void);
static void network_status_string( vg_str *str, u32 *colour );
+static void network_send_region(void);
static int network_connected(void){
if( network_client.remote_version != NETWORK_SKATERIFT_VERSION ) return 0;
#define NETWORK_MAX_PLAYERS 20
#define NETWORK_FRAMERATE 0.1
#define NETWORK_BUFFERFRAMES 6
-//#define NETWORK_LEADERBOARD_MAX_SIZE 1024
#define NETWORK_MAX_CHAT 128
+#define NETWORK_REGION_MAX 32
#define NETWORK_SKATERIFT_VERSION 8
#define NETWORK_REQUEST_MAX 2048
char msg[];
};
+typedef struct netmsg_region netmsg_region;
+enum{ k_inetmsg_region = 206 };
+struct netmsg_region {
+ u16 inetmsg_id;
+ u8 client;
+ u32 flags;
+ char loc[];
+};
+
/* requests 300 */
typedef struct netmsg_request netmsg_request;
enum{ k_inetmsg_request = 300, k_inetmsg_response = 301 };
#include "font.h"
#include "gui.h"
#include "ent_miniworld.h"
+#include "ent_region.h"
static i32 k_show_own_name = 0;
player->chat_time = vg.time_real;
vg_info( "[%d]: %s\n", chat->client, player->chat );
}
+ else if( tmp->inetmsg_id == k_inetmsg_region ){
+ netmsg_region *region = msg->m_pData;
+ struct network_player *player = &netplayers.list[ region->client ];
+
+ u32 l = network_msgstring(
+ region->loc, msg->m_cbSize, sizeof(netmsg_region),
+ player->region, NETWORK_REGION_MAX );
+ player->region_flags = region->flags;
+
+ if( l )
+ player->region_flags |= k_ent_region_flag_hasname;
+
+ player->effect_data.spark.colour = region_spark_colour(region->flags);
+ }
}
/*
if( !player->isfriend && !in_same_world )
continue;
+
+ const char *location = in_same_world? "": "another world";
+ if( player->region_flags & k_ent_region_flag_hasname ){
+ location = player->region;
+ }
ui_rect box = { x, y, width, height };
- remote_player_gui_info( box, player->username,
- in_same_world? "": "another world",
+ remote_player_gui_info( box, player->username, location,
player->isfriend, in_same_world );
y += height + gap;
}
char username[ NETWORK_USERNAME_MAX ];
char items[k_netmsg_playeritem_max][ADDON_UID_MAX];
char chat[ NETWORK_MAX_CHAT ];
+ char region[ NETWORK_REGION_MAX ];
+ u32 region_flags;
f64 chat_time;
/* ui */