Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickGTR authored Aug 17, 2021
2 parents 78a2ca2 + c68d554 commit 030e923
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gamemodes/core/account/account_login.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ hook OnPlayerConnect(playerid) {
}

// Global
void:Account_PromptLogin(playerid, const password[], len = sizeof(password)) {
void:Account_PromptLogin(playerid, const hash[], len = sizeof(hash)) {
new
playerHash[62];
// copy to local stack
// fix with y_inline scopes.
strcpy(playerHash, password, len);
strcpy(playerHash, hash, len);

inline const PromptLoginResponse(response, listitem, string:inputtext[]) {
#pragma unused listitem
Expand Down
1 change: 1 addition & 0 deletions gamemodes/core/houses/houses.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <houses_entext-handler>
#include <houses_cmd>
#include <houses_lock>
#include <houses_key_holder>

#include <furniture>

Expand Down
60 changes: 58 additions & 2 deletions gamemodes/core/houses/houses_cmd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,59 @@ CMD:buyhouse(playerid, params[]) {
return 1;
}

CMD:hgivekey(playerid, params[]) {

new
targetid;
if(sscanf(params, "u", targetid))
return SendSyntaxMsg(playerid, "/hgivekey <playerid/username>");

if(!IsPlayerConnected(targetid)) {
return SendErrorMsg(playerid, "Invalid username / targetid");
}

new
houseid = Player_GetInHouseID(playerid),
ret = House_SetKeyHolder(playerid, houseid);

if(!House_PlayerIsOwner(playerid, houseid)) {
return SendErrorMsg(playerid, "You are not the owner of this house.");
}

if(ret == -1) {
return SendErrorMsg(playerid, "This player is already a key holder.");
}

SendServerMsgF(playerid, "You have successfully added "C_GREY"%p(%i) "C_WHITE"as a key holder.", playerid, playerid);
return 1;
}

CMD:hremovekey(playerid, params[]) {
new
targetid;
if(sscanf(params, "u", targetid))
return SendSyntaxMsg(playerid, "/hgivekey <playerid/username>");

if(!IsPlayerConnected(targetid)) {
return SendErrorMsg(playerid, "Invalid username / targetid");
}

new
houseid = Player_GetInHouseID(playerid),
ret = House_RevokeKeyHolder(playerid, houseid);

if(!House_PlayerIsOwner(playerid, houseid)) {
return SendErrorMsg(playerid, "You are not the owner of this house.");
}

if(!ret) {
return SendErrorMsg(playerid, "This player is not a key holder.");
}

SendServerMsgF(playerid, "You have successfully removed "C_GREY"%p(%i) "C_WHITE"as a key holder.", playerid, playerid);
return 1;
}


CMD:hlock(playerid, params[]) {
new
Expand All @@ -32,8 +85,11 @@ CMD:hlock(playerid, params[]) {
return SendErrorMsg(playerid, "You are not in any house entrance.");
}

if(!House_PlayerIsOwner(playerid, houseid)) {
return SendErrorMsg(playerid, "You do not own this house.");
new
isKeyHolder = House_IsKeyHolder(playerid, houseid);
printf("%s", isKeyHolder ? "YES" : "NO");
if(!isKeyHolder) {
return SendErrorMsg(playerid, "You do not have a key to this house.");
}

SendServerMsgF(
Expand Down
110 changes: 110 additions & 0 deletions gamemodes/core/houses/houses_key_holder.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Module: Key holder for houses
// Date: 23/03/2021 - 12:44 AM
// Author: PatrickGTR

#include <YSI_Coding\y_hooks>

#define MAX_KEY_HOLDERS 3

static
KeyHolder[MAX_HOUSES][MAX_KEY_HOLDERS] = {-1, ...};

// re-write, do the toggle of setting on player login instead of
// init.
hook OnMySQLConnected() {

new
Statement:stmt_LoadKeyHolders;
stmt_LoadKeyHolders = MySQL_PrepareStatement(MySQL_GetHandle(), "SELECT houseid, uid FROM house_key_holders");

inline const OnHouseKeyHolderLoad() {
new
houseid,
userid;

MySQL_BindResultInt(stmt_LoadKeyHolders, 0, houseid);
MySQL_BindResultInt(stmt_LoadKeyHolders, 1, userid);
while(MySQL_Statement_FetchRow(stmt_LoadKeyHolders)) {

new
freeSlot = GetFreeSlot(houseid);

// skip, no more space.
if(freeSlot == -1) {
continue;
}

KeyHolder[houseid][freeSlot] = userid;
}
}
MySQL_ExecuteThreaded_Inline(stmt_LoadKeyHolders, using inline OnHouseKeyHolderLoad);
}

static GetFreeSlot(houseid) {
new
id = -1;

for(new i = 0; i < MAX_KEY_HOLDERS; i++) {
if(KeyHolder[houseid][i] == -1) {
id = i;
break;
}
}
return id;
}

House_IsKeyHolder(playerid, houseid) {

// if player is an owner, he's obviously a key holder.
// no point of running the code below.
// terminate here
if(House_PlayerIsOwner(playerid, houseid)) {
return 1;
}

new
bool:ret = false;

for(new i = 0; i < MAX_KEY_HOLDERS; i++) {
new
accountid = Player_GetAccountID(playerid);
if(KeyHolder[houseid][i] == accountid) {
ret = true;
break;
}
}
return ret;
}

// return values
// -1 -> playerid already a key holder
// 0 -> invalid player
// 1 -> success
House_SetKeyHolder(playerid, houseid) {
new
accountid = Player_GetAccountID(playerid),
freeSlot = GetFreeSlot(houseid);

// no more slot left
if(freeSlot == -1) {
return 0;
}

KeyHolder[houseid][freeSlot] = accountid;
return 1;
}

House_RevokeKeyHolder(playerid, houseid) {
new
accountid = Player_GetAccountID(playerid), index;

for(new i = 0; i < MAX_KEY_HOLDERS; i++) {
if(KeyHolder[houseid][i] == accountid) {
index = i;
break;
}
}

KeyHolder[houseid][index] = -1;
return 1;
}
14 changes: 13 additions & 1 deletion gamemodes/core/server/server_tax.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ const WEEKLY_TAX_PERCENTANGE = 10;

hook OnPlayerDeathEx(playerid, killerid, reason) {
new
cashInHand = GetPlayerMoney(playerid) + Player_GetBankMoney(playerid),
cashInHand = GetPlayerMoney(playerid) + Player_GetBankMoney(playerid);

if(cashInHand > 50_000) {
return 1;
}

new
tax = (cashInHand / 100) * DEATH_TAX_PERCENTAGE;

MessageBox_ShowF(
Expand Down Expand Up @@ -34,6 +40,11 @@ hook OnServerWeekReset() {
}

cashInHand = GetPlayerMoney(playerid) + Player_GetBankMoney(playerid);

if(cashInHand > 50_000) {
continue;
}

tax = (cashInHand / 100) * WEEKLY_TAX_PERCENTANGE;

MessageBox_ShowF(
Expand All @@ -55,6 +66,7 @@ hook OnServerWeekReset() {
stock Server_GetMoney() {
return GetSVarInt("SERVER_MONEY");
}

Server_GiveMoney(amount) {
SetSVarInt("SERVER_MONEY", Server_GetMoney() + amount);
}
2 changes: 1 addition & 1 deletion scriptfiles/atms.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ CREATE TABLE IF NOT EXISTS atms (
wid tinyint(6) NOT NULL,
interior tinyint(6) NOT NULL,
PRIMARY KEY (atm_id)
);
);
25 changes: 24 additions & 1 deletion scriptfiles/houses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS player_houses (
entrance_a FLOAT NOT NULL,
interior_id TINYINT(4) NOT NULL,
virtual_world MEDIUMINT NOT NULL,
PRIMARY KEY
UNIQUE KEY
(house_id),
FOREIGN KEY
(u_id)
Expand All @@ -38,6 +38,29 @@ CREATE TABLE IF NOT EXISTS house_settings (
CASCADE
);

CREATE TABLE IF NOT EXISTS house_key_holders (
houseid smallint(6) NOT NULL,
uid int(11) NOT NULL,
PRIMARY KEY (houseid),
KEY uid (uid),
FOREIGN KEY
(houseid)
REFERENCES
player_houses (house_id)
ON DELETE
CASCADE
ON UPDATE
CASCADE,
FOREIGN KEY
(uid)
REFERENCES
players (u_id)
ON DELETE
CASCADE
ON UPDATE
CASCADE
);

CREATE TABLE IF NOT EXISTS house_furniture (
furniture_id INT(11) AUTO_INCREMENT,
house_id SMALLINT(6) NOT NULL,
Expand Down
6 changes: 3 additions & 3 deletions scriptfiles/players.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ CREATE TABLE IF NOT EXISTS players
(
u_id int(11) NOT NULL AUTO_INCREMENT,
username varchar(24) NOT NULL,
password char(250) NOT NULL,
password char(60) NOT NULL,
register_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(),
last_login DATETIME DEFAULT NULL,
last_login DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY
(u_id),
UNIQUE KEY
username (username)
);
);

0 comments on commit 030e923

Please sign in to comment.