Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate some missing Friends and Matchmaking functions #41

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
13 changes: 10 additions & 3 deletions src/apps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ EXTERN int luasteam_getLaunchCommandLine(lua_State *L) {
return 1;
}

// int GetLaunchCommandLine( char *pszCommandLine, int cubCommandLine );
EXTERN int luasteam_getLaunchCommandLine(lua_State *L) {
char buffer[256];
int bytes = SteamApps()->GetLaunchCommandLine(buffer, sizeof(buffer) - 1);
buffer[bytes] = '\0';
lua_pushstring(L, buffer);
return 1;
}

namespace luasteam {

void add_apps(lua_State *L) {
Expand All @@ -64,9 +73,7 @@ void add_apps(lua_State *L) {
lua_setfield(L, -2, "apps");
}

void init_apps(lua_State *L) {
apps_listener = new CallbackListener();
}
void init_apps(lua_State *L) { apps_listener = new CallbackListener(); }

void shutdown_apps(lua_State *L) {
luaL_unref(L, LUA_REGISTRYINDEX, apps_ref);
Expand Down
8 changes: 8 additions & 0 deletions src/const.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
static const char *steam_result_code[] = {
"None", "OK", "Fail", "NoConnection", "NoConnectionRetry", "InvalidPassword", "LoggedInElsewhere", "InvalidProtocolVer", "InvalidParam", "FileNotFound", "Busy", "InvalidState", "InvalidName", "InvalidEmail", "DuplicateName", "AccessDenied", "Timeout", "Banned", "AccountNotFound", "InvalidSteamID", "ServiceUnavailable", "NotLoggedOn", "Pending", "EncryptionFailure", "InsufficientPrivilege", "LimitExceeded", "Revoked", "Expired", "AlreadyRedeemed", "DuplicateRequest", "AlreadyOwned", "IPNotFound", "PersistFailed", "LockingFailed", "LogonSessionReplaced", "ConnectFailed", "HandshakeFailed", "IOFailure", "RemoteDisconnect", "ShoppingCartNotFound", "Blocked", "Ignored", "NoMatch", "AccountDisabled", "ServiceReadOnly", "AccountNotFeatured", "AdministratorOK", "ContentVersion", "TryAnotherCM", "PasswordRequiredToKickSession", "AlreadyLoggedInElsewhere", "Suspended", "Cancelled", "DataCorruption", "DiskFull", "RemoteCallFailed", "PasswordUnset", "ExternalAccountUnlinked", "PSNTicketInvalid", "ExternalAccountAlreadyLinked", "RemoteFileConflict", "IllegalPassword", "SameAsPreviousValue", "AccountLogonDenied", "CannotUseOldPassword", "InvalidLoginAuthCode", "AccountLogonDeniedNoMail", "HardwareNotCapableOfIPT", "IPTInitError", "ParentalControlRestricted", "FacebookQueryError", "ExpiredLoginAuthCode", "IPLoginRestrictionFailed", "AccountLockedDown", "AccountLogonDeniedVerifiedEmailRequired", "NoMatchingURL", "BadResponse", "RequirePasswordReEntry", "ValueOutOfRange", "UnexpectedError", "Disabled", "InvalidCEGSubmission", "RestrictedDevice", "RegionLocked", "RateLimitExceeded", "AccountLoginDeniedNeedTwoFactor", "ItemDeleted", "AccountLoginDeniedThrottle", "TwoFactorCodeMismatch", "TwoFactorActivationCodeMismatch", "AccountAssociatedToMultiplePartners", "NotModified", "NoMobileDevice", "TimeNotSynced", "SmsCodeFailed", "AccountLimitExceeded", "AccountActivityLimitExceeded", "PhoneActivityLimitExceeded", "RefundToWallet", "EmailSendFailure", "NotSettled", "NeedCaptcha", "GSLTDenied", "GSOwnerDenied", "InvalidItemType", "IPBanned", "GSLTExpired", "InsufficientFunds", "TooManyPending", "NoSiteLicensesFound", "WGNetworkSendExceeded", "AccountNotFriends", "LimitedUserAccount", "CantRemoveItem", "AccountDeleted", "ExistingUserCancelledLicense", "CommunityCooldown", "NoLauncherSpecified", "MustAgreeToSSA", "LauncherMigrated", "SteamRealmMismatch", "InvalidSignature", "ParseFailure", "NoVerifiedPhone", "InsufficientBattery", "ChargerRequired", "CachedCredentialInvalid", "PhoneNumberIsVOIP", nullptr,
};

static const char *chat_entry_type[] = {
"Invalid", "ChatMsg", "Typing", "InviteGame", "Emote", "LeftConversation", "Entered", "WasKicked", "WasBanned", "Disconnected", "HistoricalChat", "LinkBlocked", nullptr,
};

static const char *chat_room_enter_response[] = {
"None", "Success", "DoesntExist", "NotAllowed", "Full", "Error", "Banned", "Limited", "ClanDisabled", "CommunityBan", "MemberBlockedYou", "YouBlockedMember", "RateLimitExceeded", nullptr,
};
12 changes: 12 additions & 0 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "input.hpp"
#include "networkingSockets.hpp"
#include "networkingUtils.hpp"
#include "matchmaking.hpp"

// ========================
// ======= SteamAPI =======
Expand All @@ -27,17 +28,27 @@ EXTERN int luasteam_init(lua_State *L) {
luasteam::init_input(L);
luasteam::init_networkingSockets(L);
luasteam::init_networkingUtils(L);
luasteam::init_matchmaking(L);
} else {
fprintf(stderr, "Couldn't connect to steam...\nDo you have Steam turned on?\nIf not running from steam, do you have a correct steam_appid.txt file?\n");
}
lua_pushboolean(L, success);
return 1;
}

// bool SteamAPI_RestartAppIfNecessary( uint32 unOwnAppID );
EXTERN int luasteam_restartAppIfNecessary(lua_State *L) {
int ownAppID = luaL_checkinteger(L, 1);
bool success = SteamAPI_RestartAppIfNecessary(ownAppID);
lua_pushboolean(L, success);
return 1;
}

// void SteamAPI_Shutdown();
EXTERN int luasteam_shutdown(lua_State *L) {
SteamAPI_Shutdown();
// Cleaning up
luasteam::shutdown_matchmaking(L);
luasteam::shutdown_networkingUtils(L);
luasteam::shutdown_networkingSockets(L);
luasteam::shutdown_input(L);
Expand All @@ -63,6 +74,7 @@ void add_core(lua_State *L) {
add_func(L, "init", luasteam_init);
add_func(L, "shutdown", luasteam_shutdown);
add_func(L, "runCallbacks", luasteam_runCallbacks);
add_func(L, "restartAppIfNecessary", luasteam_restartAppIfNecessary);
}

} // namespace luasteam
81 changes: 81 additions & 0 deletions src/friends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,34 @@ const char *dialog_types[] = {"friends", "community", "players", "settings", "of

class CallbackListener {
private:
STEAM_CALLBACK(CallbackListener, OnGameLobbyJoinRequested, GameLobbyJoinRequested_t);
STEAM_CALLBACK(CallbackListener, OnGameOverlayActivated, GameOverlayActivated_t);
STEAM_CALLBACK(CallbackListener, OnGameRichPresenceJoinRequested, GameRichPresenceJoinRequested_t);
};

void CallbackListener::OnGameLobbyJoinRequested(GameLobbyJoinRequested_t *data) {
if (data == nullptr) {
return;
}
lua_State *L = luasteam::global_lua_state;
if (!lua_checkstack(L, 4)) {
return;
}
lua_rawgeti(L, LUA_REGISTRYINDEX, friends_ref);
lua_getfield(L, -1, "onGameLobbyJoinRequested");
if (lua_isnil(L, -1)) {
lua_pop(L, 2);
} else {
lua_createtable(L, 0, 2);
luasteam::pushuint64(L, data->m_steamIDLobby.ConvertToUint64());
lua_setfield(L, -2, "lobby");
luasteam::pushuint64(L, data->m_steamIDFriend.ConvertToUint64());
lua_setfield(L, -2, "friend");
lua_call(L, 1, 0);
lua_pop(L, 1);
}
}

void CallbackListener::OnGameOverlayActivated(GameOverlayActivated_t *data) {
if (data == nullptr) {
return;
Expand Down Expand Up @@ -72,6 +96,13 @@ EXTERN int luasteam_activateGameOverlay(lua_State *L) {
return 0;
}

// void ActivateGameOverlayInviteDialog( CSteamID steamIDLobby );
EXTERN int luasteam_activateGameOverlayInviteDialog(lua_State *L) {
CSteamID lobby(luasteam::checkuint64(L, 1));
SteamFriends()->ActivateGameOverlayInviteDialog(lobby);
return 0;
}

// void ActivateGameOverlayToWebPage( const char *pchURL );
EXTERN int luasteam_activateGameOverlayToWebPage(lua_State *L) {
const char *url = luaL_checkstring(L, 1);
Expand All @@ -87,6 +118,52 @@ EXTERN int luasteam_getFriendPersonaName(lua_State *L) {
return 1;
}

// const char * GetPersonaName();
EXTERN int luasteam_getPersonaName(lua_State *L) {
const char *name = SteamFriends()->GetPersonaName();
lua_pushstring(L, name);
return 1;
}

static int luasteam_getImage(lua_State *L, int handle)
{
uint32 width, height;
SteamUtils()->GetImageSize(handle, &width, &height);
lua_getglobal(L, "love");
lua_getfield(L, -1, "image");
lua_getfield(L, -1, "newImageData");
lua_pushinteger(L, width);
lua_pushinteger(L, height);
lua_call(L, 2, 1);
lua_getfield(L, -1, "getPointer");
lua_pushvalue(L, -2);
lua_call(L, 1, 1);
uint8 *buffer = (uint8*)lua_topointer(L, -1);
SteamUtils()->GetImageRGBA(handle, buffer, width * height * 4);
lua_pop(L, 1);
lua_getfield(L, -3, "graphics");
lua_getfield(L, -1, "newImage");
lua_replace(L, -4);
lua_pop(L, 1);
lua_call(L, 1, 1);
lua_replace(L, -2);
return 1;
}

// int GetLargeFriendAvatar( CSteamID steamIDFriend );
EXTERN int luasteam_getLargeFriendAvatar(lua_State *L) {
CSteamID id(luasteam::checkuint64(L, 1));
int handle = SteamFriends()->GetLargeFriendAvatar(id);
return luasteam_getImage(L, handle);
}

// int GetMediumFriendAvatar( CSteamID steamIDFriend );
EXTERN int luasteam_getMediumFriendAvatar(lua_State *L) {
CSteamID id(luasteam::checkuint64(L, 1));
int handle = SteamFriends()->GetMediumFriendAvatar(id);
return luasteam_getImage(L, handle);
}

// bool SetRichPresence( const char *pchKey, const char *pchValue );
EXTERN int luasteam_setRichPresence(lua_State *L) {
const char *key = luaL_checkstring(L, 1);
Expand Down Expand Up @@ -130,8 +207,12 @@ namespace luasteam {
void add_friends(lua_State *L) {
lua_createtable(L, 0, 7);
add_func(L, "activateGameOverlay", luasteam_activateGameOverlay);
add_func(L, "activateGameOverlayInviteDialog", luasteam_activateGameOverlayInviteDialog);
add_func(L, "activateGameOverlayToWebPage", luasteam_activateGameOverlayToWebPage);
add_func(L, "getFriendPersonaName", luasteam_getFriendPersonaName);
add_func(L, "getLargeFriendAvatar", luasteam_getLargeFriendAvatar);
add_func(L, "getMediumFriendAvatar", luasteam_getMediumFriendAvatar);
add_func(L, "getPersonaName", luasteam_getPersonaName);
add_func(L, "setRichPresence", luasteam_setRichPresence);
add_func(L, "inviteUserToGame", luasteam_inviteUserToGame);
add_func(L, "getFriendCount", luasteam_getFriendCount);
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "input.hpp"
#include "networkingSockets.hpp"
#include "networkingUtils.hpp"
#include "matchmaking.hpp"
#include "gameServer.hpp"

// Creates and returns a table with all functions
Expand All @@ -26,6 +27,7 @@ EXTERN int luaopen_luasteam(lua_State *L) {
luasteam::add_input(L);
luasteam::add_networkingSockets(L);
luasteam::add_networkingUtils(L);
luasteam::add_matchmaking(L);
luasteam::add_gameServer(L);
return 1;
}
Loading