125 lines
3.3 KiB
C
125 lines
3.3 KiB
C
/*
|
|
* casino_portable.h - Cross-Platform Assembler Casino Engine Header
|
|
* Version 2.0: Cloud Sync, Account Transfer Keys & P2P Anti-Cheat Authentication
|
|
*/
|
|
|
|
#ifndef CASINO_PORTABLE_H
|
|
#define CASINO_PORTABLE_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <time.h>
|
|
|
|
#ifdef _WIN32
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
#include <windows.h>
|
|
#include <conio.h>
|
|
#pragma comment(lib, "ws2_32.lib")
|
|
#define SOCKET_TYPE SOCKET
|
|
#define IS_INVALID_SOCKET(s) ((s) == INVALID_SOCKET)
|
|
#define CLOSESOCKET(s) closesocket(s)
|
|
#else
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
#include <termios.h>
|
|
#include <sys/select.h>
|
|
#define SOCKET_TYPE int
|
|
#define INVALID_SOCKET (-1)
|
|
#define SOCKET_ERROR (-1)
|
|
#define IS_INVALID_SOCKET(s) ((s) < 0)
|
|
#define CLOSESOCKET(s) close(s)
|
|
#endif
|
|
|
|
#define CASINO_PORT 27015
|
|
#define MAX_LOBBY_ROOMS 10
|
|
#define MAX_ROOM_NAME 32
|
|
#define MAX_PASS_LEN 32
|
|
#define MAX_NAME_LEN 32
|
|
#define TRANSFER_KEY_LEN 19
|
|
#define SAVE_MAGIC 0x31435653
|
|
#define SAVE_SALT_MAGIC 0xA57C0DE
|
|
|
|
/* Password Salted Hash & Account Structure */
|
|
typedef struct {
|
|
uint32_t magic;
|
|
uint32_t salt;
|
|
uint32_t password_hash;
|
|
uint64_t bank_balance;
|
|
uint32_t wins;
|
|
uint32_t losses;
|
|
uint32_t signature;
|
|
char username[MAX_NAME_LEN];
|
|
} AccountData;
|
|
|
|
/* Network Packet Commands */
|
|
typedef enum {
|
|
NET_CMD_HOST_ROOM = 1,
|
|
NET_CMD_LIST_ROOMS,
|
|
NET_CMD_JOIN_ROOM,
|
|
NET_CMD_LOBBY_STATE,
|
|
NET_CMD_PLAYER_READY,
|
|
NET_CMD_START_GAME,
|
|
NET_CMD_CHAT_MSG,
|
|
NET_CMD_AUTH_CHALLENGE,
|
|
NET_CMD_AUTH_RESPONSE,
|
|
NET_CMD_AUTH_REJECTED
|
|
} NetCmdType;
|
|
|
|
/* Network Packet Header */
|
|
typedef struct {
|
|
uint8_t cmd;
|
|
uint8_t room_id;
|
|
uint16_t data_len;
|
|
} NetPacketHeader;
|
|
|
|
/* Challenge-Response Anti-Cheat Packet */
|
|
typedef struct {
|
|
uint32_t challenge_nonce;
|
|
uint32_t client_signature;
|
|
char username[MAX_NAME_LEN];
|
|
} AuthChallengePacket;
|
|
|
|
/* Room Info Structure */
|
|
typedef struct {
|
|
uint8_t room_id;
|
|
char room_name[MAX_ROOM_NAME];
|
|
char host_name[MAX_NAME_LEN];
|
|
uint8_t max_players;
|
|
uint8_t current_players;
|
|
uint8_t game_type;
|
|
bool has_password;
|
|
char password[MAX_PASS_LEN];
|
|
} RoomInfo;
|
|
|
|
/* Platform Helpers */
|
|
void platform_init(void);
|
|
void platform_cleanup(void);
|
|
void clear_screen(void);
|
|
void set_text_color(const char* color_code);
|
|
char get_masked_char(void);
|
|
void read_masked_password(char* out_pass, size_t max_len);
|
|
uint32_t hash_password(const char* password, uint32_t salt);
|
|
uint32_t calc_account_signature(const AccountData* acc);
|
|
|
|
/* Account System & Transfer */
|
|
bool account_register(AccountData* acc);
|
|
bool account_login(AccountData* acc);
|
|
bool account_save(const AccountData* acc);
|
|
void account_generate_transfer_key(const AccountData* acc, char* out_key);
|
|
bool account_import_transfer_key(AccountData* acc, const char* key, const char* new_pass);
|
|
bool account_cloud_sync_upload(const AccountData* acc);
|
|
bool account_cloud_sync_download(AccountData* acc, const char* username, const char* password);
|
|
|
|
/* Network Lobby System & P2P Anti-Cheat */
|
|
void net_lobby_menu(AccountData* acc);
|
|
bool verify_peer_account_signature(uint32_t nonce, uint32_t signature, uint32_t expected_hash);
|
|
|
|
#endif /* CASINO_PORTABLE_H */
|