Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ endif
LFLAGS = -lhl -lsteam_api -lstdc++ -L sdk/redistributable_bin/$(OS)$(ARCH)

SRC = native/cloud.o native/common.o native/controller.o native/friends.o native/gameserver.o \
native/matchmaking.o native/networking.o native/stats.o native/ugc.o
native/matchmaking.o native/networking.o native/networkingmessages.o native/stats.o \
native/ugc.o

all: ${SRC}
${CC} ${CFLAGS} -shared -o steam.hdll ${SRC} ${LFLAGS}
Expand Down
1 change: 1 addition & 0 deletions hlsteam.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
<ClCompile Include="native\gameserver.cpp" />
<ClCompile Include="native\matchmaking.cpp" />
<ClCompile Include="native\networking.cpp" />
<ClCompile Include="native\networkingmessages.cpp" />
<ClCompile Include="native\stats.cpp" />
<ClCompile Include="native\ugc.cpp" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions hlsteam.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<ClCompile Include="native\cloud.cpp" />
<ClCompile Include="native\friends.cpp" />
<ClCompile Include="native\networking.cpp" />
<ClCompile Include="native\networkingmessages.cpp" />
<ClCompile Include="native\timeline.cpp" />
<ClCompile Include="native\gameserver.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions native/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ EVENT_DECL( LobbyJoinRequest, GameLobbyJoinRequested_t )
// networking
EVENT_DECL( P2PSessionRequest, P2PSessionRequest_t )
EVENT_DECL( P2PSessionConnectionFail, P2PSessionConnectFail_t )
EVENT_DECL( SteamNetworkingMessagesSessionRequest, SteamNetworkingMessagesSessionRequest_t )
EVENT_DECL( SteamNetworkingMessagesSessionFailed, SteamNetworkingMessagesSessionFailed_t )

EVENT_DECL( GameRichPresenceJoinRequested, GameRichPresenceJoinRequested_t )

// ugc
EVENT_DECL(DownloadItem, DownloadItemResult_t)
Expand Down
5 changes: 5 additions & 0 deletions native/matchmaking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ HL_PRIM void HL_NAME(set_lobby_member_limit)( vuid uid, int count ) {
SteamMatchmaking()->SetLobbyMemberLimit(hl_to_uid(uid), count);
}

HL_PRIM void HL_NAME(set_lobby_type)( vuid uid, ELobbyType lobbyType ) {
SteamMatchmaking()->SetLobbyType(hl_to_uid(uid), lobbyType);
}

DEFINE_PRIM(_CRESULT, create_lobby, _I32 _I32 _CALLB(_UID));
DEFINE_PRIM(_VOID, leave_lobby, _UID);
DEFINE_PRIM(_CRESULT, join_lobby, _UID _CALLB(_BOOL));
Expand All @@ -164,6 +168,7 @@ DEFINE_PRIM(_I32, get_num_lobby_members, _UID);
DEFINE_PRIM(_UID, get_lobby_member_by_index, _UID _I32);
DEFINE_PRIM(_I32, get_lobby_member_limit, _UID);
DEFINE_PRIM(_VOID, set_lobby_member_limit, _UID _I32);
DEFINE_PRIM(_VOID, set_lobby_type, _UID _I32);

DEFINE_PRIM(_UID, get_lobby_owner, _UID);
DEFINE_PRIM(_VOID, lobby_invite_friends, _UID);
Expand Down
106 changes: 106 additions & 0 deletions native/networkingmessages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "steamwrap.h"

SteamNetworkingIdentity hl_to_steamnetid(steamnetid v) {
union {
vbyte b[sizeof(SteamNetworkingIdentity)];
SteamNetworkingIdentity v;
} data;
memcpy(data.b, v, sizeof(SteamNetworkingIdentity));
return SteamNetworkingIdentity(data.v);
}

steamnetid hl_of_steamnetid(SteamNetworkingIdentity v) {
union {
vbyte b[sizeof(SteamNetworkingIdentity)];
SteamNetworkingIdentity v;
} data;
data.v = v;
return (steamnetid)hl_copy_bytes(data.b, sizeof(SteamNetworkingIdentity));
}

HL_PRIM steamnetid HL_NAME(get_identity)() {
SteamNetworkingIdentity identity;
SteamNetworkingSockets()->GetIdentity(&identity);
return hl_of_steamnetid(identity);
}

HL_PRIM vbyte* HL_NAME(identity_to_string)(steamnetid identity) {
char *buf = (char *)hl_gc_alloc_noptr(SteamNetworkingIdentity::k_cchMaxString);
hl_to_steamnetid(identity).ToString(buf, SteamNetworkingIdentity::k_cchMaxString);
return (vbyte*)buf;
}

HL_PRIM vbyte* HL_NAME(identity_from_string)(vbyte* v) {
SteamNetworkingIdentity identity;
identity.ParseString((char*)v);
return hl_of_steamnetid(identity);
}

DEFINE_PRIM(_STEAMNETID, get_identity, _NO_ARG);
DEFINE_PRIM(_BYTES, identity_to_string, _STEAMNETID);
DEFINE_PRIM(_STEAMNETID, identity_from_string, _BYTES);

HL_PRIM void HL_NAME(init_authentication)() {
SteamNetworkingSockets()->InitAuthentication();
}

HL_PRIM bool HL_NAME(accept_session_with_user)(steamnetid identity) {
return SteamNetworkingMessages()->AcceptSessionWithUser(hl_to_steamnetid(identity));
}

HL_PRIM bool HL_NAME(close_session_with_user)(steamnetid identity) {
return SteamNetworkingMessages()->CloseSessionWithUser(hl_to_steamnetid(identity));
}

HL_PRIM int HL_NAME(send_message_to_user)(steamnetid identityRemote, vbyte* pubData, int cubData, int nSendFlags, int nRemoteChannel) {
return SteamNetworkingMessages()->SendMessageToUser(hl_to_steamnetid(identityRemote), pubData, cubData, nSendFlags, nRemoteChannel);
}

DEFINE_PRIM(_VOID, init_authentication, _NO_ARG);
DEFINE_PRIM(_BOOL, accept_session_with_user, _STEAMNETID);
DEFINE_PRIM(_BOOL, close_session_with_user, _STEAMNETID);
DEFINE_PRIM(_I32, send_message_to_user, _STEAMNETID _BYTES _I32 _I32 _I32);

vdynamic *CallbackHandler::EncodeSteamNetworkingMessagesSessionRequest(SteamNetworkingMessagesSessionRequest_t *d) {
HLValue ret;
ret.Set("identity", d->m_identityRemote);
return ret.value;
}

vdynamic *CallbackHandler::EncodeSteamNetworkingMessagesSessionFailed(SteamNetworkingMessagesSessionFailed_t *d) {
HLValue ret;
// ret.Set("info", d->m_info);
printf("%d %s", d->m_info.m_eEndReason, d->m_info.m_szEndDebug);
return ret.value;
}

vdynamic *CallbackHandler::EncodeGameRichPresenceJoinRequested(GameRichPresenceJoinRequested_t *d) {
HLValue ret;
ret.Set("friend", d->m_steamIDFriend);
ret.Set("connect", d->m_rgchConnect);
return ret.value;
}

HL_PRIM SteamNetworkingMessage_t* HL_NAME(receive_message_on_channel)(int nLocalChannel) {
SteamNetworkingMessage_t* message = NULL;
SteamNetworkingMessages()->ReceiveMessagesOnChannel(nLocalChannel, &message, 1);
return message;
}

HL_PRIM void HL_NAME(release_message)(SteamNetworkingMessage_t* message) {
message->Release();
}

HL_PRIM int HL_NAME(get_message_size)(SteamNetworkingMessage_t* message) {
return message->GetSize();
}

HL_PRIM vbyte* HL_NAME(get_message_data)(SteamNetworkingMessage_t* message) {
return (vbyte*)message->GetData();
}

#define NWMSG _ABSTRACT(steam_networkmsg)
DEFINE_PRIM(NWMSG, receive_message_on_channel, _I32);
DEFINE_PRIM(_VOID, release_message, NWMSG);
DEFINE_PRIM(_I32, get_message_size, NWMSG);
DEFINE_PRIM(_BYTES, get_message_data, NWMSG);
7 changes: 7 additions & 0 deletions native/steamwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include <steam/isteamappticket.h>

typedef vbyte * vuid;
typedef vbyte * steamnetid;
#define _UID _BYTES
#define _STEAMNETID _BYTES
#define hlt_uid hlt_bytes

void dyn_call_result( vclosure *c, vdynamic *p, bool error );
Expand All @@ -25,6 +27,8 @@ CSteamID hl_to_uid( vuid v );
vuid hl_of_uid( CSteamID id );
uint64 hl_to_uint64(vuid v);
vuid hl_of_uint64(uint64 id);
SteamNetworkingIdentity hl_to_steamnetid(steamnetid v);
steamnetid hl_of_steamnetid(SteamNetworkingIdentity v);

template< class T >
class CClosureCallResult : public CCallResult<CClosureCallResult<T>,T> {
Expand Down Expand Up @@ -110,6 +114,9 @@ class HLValue {
void Set( const char *name, uint64 uid ) {
hl_dyn_setp(value, hl_hash_utf8(name), &hlt_uid, hl_of_uint64(uid));
}
void Set( const char *name, SteamNetworkingIdentity uid ) {
hl_dyn_setp(value, hl_hash_utf8(name), &hlt_uid, hl_of_steamnetid(uid));
}
void Set( const char *name, uint32 v ) {
Set(name,(int)v);
}
Expand Down
22 changes: 22 additions & 0 deletions steam/Api.hx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Api
// User-settable Callbacks

public static var onOverlay : Bool -> Void;
public static var onGameRichPresenceJoinRequested: UID -> String -> Void;

/**
* @param appId_ Your Steam APP ID (the numbers on the end of your store page URL - store.steampowered.com/app/XYZ)
Expand Down Expand Up @@ -92,6 +93,24 @@ class Api
}
});

// SteamNetworkingMessagesSessionRequest_t
registerGlobalEvent(1250 + 1, function(data:{identity: SteamNetworkingIdentity}){
if( NetworkingMessages.onSessionRequest != null )
NetworkingMessages.onSessionRequest(data.identity);
});

// SteamNetworkingMessagesSessionFailed_t
registerGlobalEvent(1250 + 2, function(data:{info: SteamNetConnectionInfo}){
// if( NetworkingMessages.onSessionRequest != null )
// NetworkingMessages.onSessionRequest(data.info);
});

// GameRichPresenceJoinRequested_t
registerGlobalEvent(300 + 37, function(data:{friend: UID, connect:hl.Bytes}){
if( onGameRichPresenceJoinRequested != null )
onGameRichPresenceJoinRequested(data.friend, @:privateAccess String.fromUTF8(data.connect));
});

// if we get this far, the dlls loaded ok and we need Steam to init.
// otherwise, we're trying to run the Steam version without the Steam client
active = _Init(steamWrap_onEvent, onGlobalEvent);
Expand All @@ -114,6 +133,7 @@ class Api

static var globalEvents = new Map<Int,Dynamic->Void>();
static var authTicketCallbacks : Map<Int, Bool->Void> = new Map();
static var authTicketForWebApiCallbacks : Map<Int, (result:Int, data:haxe.io.Bytes)->Void> = new Map();

@:noComplete public static function registerGlobalEvent( event : Int, callb : Dynamic -> Void ) {
globalEvents.set(event, callb);
Expand Down Expand Up @@ -538,6 +558,8 @@ class Api
@:hlNative("?steam","is_steam_running_on_steam_deck") private static function _IsSteamRunningOnSteamDeck() : Bool { return false; }
@:hlNative("steam","is_steam_running") private static function _IsSteamRunning() : Bool { return false; }
@:hlNative("steam","get_current_game_language") private static function _GetCurrentGameLanguage() : hl.Bytes { return null; }
@:hlNative("?steam","get_launch_command_line") private static function _GetLaunchCommandLine() : hl.Bytes { return null; }
@:hlNative("?steam","get_launch_query_param") private static function _GetLaunchQueryParam( name : hl.Bytes ) : hl.Bytes { return null; }
@:hlNative("steam","get_auth_ticket") private static function _GetAuthTicket( size : hl.Ref<Int>, authTicket : hl.Ref<Int> ) : hl.Bytes { return null; }
@:hlNative("?steam","request_encrypted_app_ticket") private static function _RequestEncryptedAppTicket( data : hl.Bytes, size : Int, encryptedAppTicket : (hl.Bytes, Int) -> Void ) : Void { return; }
@:hlNative("steam","open_overlay") private static function _OpenOverlay( url : hl.Bytes ) : Bool { return false; }
Expand Down
7 changes: 7 additions & 0 deletions steam/Lobby.hx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class Lobby {
return v;
}

public function setLobbyType(v) {
set_lobby_type(uid, v);
}

// --- HL stubs ----

static function request_lobby_data( uid : UID ) {
Expand Down Expand Up @@ -251,4 +255,7 @@ class Lobby {
static function set_lobby_member_limit( uid : UID, count : Int ) {
}

static function set_lobby_type( uid : UID, count : Matchmaking.LobbyKind ) {
}

}
30 changes: 30 additions & 0 deletions steam/NetworkingMessages.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package steam;

private typedef NetworkMessage = hl.Abstract<"steam_networkmsg">;

@:hlNative("steam")
class NetworkingMessages {
public static function getIdentity():SteamNetworkingIdentity return null;
public static function identityToString(identity) return @:privateAccess String.fromUTF8(_IdentityToString(identity));
public static function identityFromString(v:String) return @:privateAccess _IdentityFromString(v.toUtf8());

public static function initAuthentication() {}
public static function acceptSessionWithUser(identity:SteamNetworkingIdentity):Bool return false;
public static function closeSessionWithUser(identity:SteamNetworkingIdentity):Bool return false;
public static function sendMessageToUser(identity:SteamNetworkingIdentity, data:haxe.io.Bytes, length:Int, nSendFlags:Int, nRemoteChannel:Int):Int {
return _SendMessageToUser(identity, hl.Bytes.fromBytes(data), length, nSendFlags, nRemoteChannel);
}
public static var onSessionRequest:SteamNetworkingIdentity -> Void;

public static function receiveMessageOnChannel(channel:Int):NetworkMessage return null;
public static function releaseMessage(msg:NetworkMessage) {}
public static function getMessageSize(msg:NetworkMessage):Int return -1;
public static function getMessageData(msg:NetworkMessage):haxe.io.Bytes {
return _GetMessageData(msg).toBytes(getMessageSize(msg));
}

@:hlNative("?steam", "identity_to_string") private static function _IdentityToString(identity:SteamNetworkingIdentity):hl.Bytes return null;
@:hlNative("?steam", "identity_from_string") private static function _IdentityFromString(v:hl.Bytes):SteamNetworkingIdentity return null;
@:hlNative("?steam", "send_message_to_user") private static function _SendMessageToUser(identity:SteamNetworkingIdentity, pubData:hl.Bytes, cubData:Int, nSendFlags:Int, nRemoteChannel:Int):Int return -1;
@:hlNative("?steam", "get_message_data") private static function _GetMessageData(msg:NetworkMessage):hl.Bytes return null;
}
7 changes: 7 additions & 0 deletions steam/SteamNetConnectionInfo.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package steam;

abstract SteamNetConnectionInfo(hl.Bytes) {
public function new(b) {
this = b;
}
}
7 changes: 7 additions & 0 deletions steam/SteamNetworkingIdentity.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package steam;

abstract SteamNetworkingIdentity(hl.Bytes) {
public function new(b) {
this = b;
}
}