added being able to create a host on the game server now need to work on joining that game
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
CHAT: A chat client/server using the SDL example network library
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Convert four letters into a number */
|
||||
#define MAKE_NUM(A, B, C, D) (((A+B)<<8)|(C+D))
|
||||
|
||||
/* Defines for the chat client */
|
||||
#define CHAT_SCROLLBACK 512 /* Save 512 lines in scrollback */
|
||||
#define CHAT_PROMPT "> "
|
||||
#define CHAT_PACKETSIZE 256 /* Maximum length of a message */
|
||||
|
||||
/* Defines shared between the server and client */
|
||||
#define CHAT_PORT MAKE_NUM('C','H','A','T')
|
||||
|
||||
/* The protocol between the chat client and server */
|
||||
#define CHAT_HELLO 0 /* 0+Port+len+name */
|
||||
#define CHAT_HELLO_PORT 1
|
||||
#define CHAT_HELLO_NLEN CHAT_HELLO_PORT+2
|
||||
#define CHAT_HELLO_NAME CHAT_HELLO_NLEN+1
|
||||
#define CHAT_ADD 1 /* 1+N+IP+Port+len+name */
|
||||
#define CHAT_ADD_SLOT 1
|
||||
#define CHAT_ADD_HOST CHAT_ADD_SLOT+1
|
||||
#define CHAT_ADD_PORT CHAT_ADD_HOST+4
|
||||
#define CHAT_ADD_NLEN CHAT_ADD_PORT+2
|
||||
#define CHAT_ADD_NAME CHAT_ADD_NLEN+1
|
||||
#define CHAT_DEL 2 /* 2+N */
|
||||
#define CHAT_DEL_SLOT 1
|
||||
#define CHAT_DEL_LEN CHAT_DEL_SLOT+1
|
||||
#define CHAT_BYE 255 /* 255 */
|
||||
#define CHAT_BYE_LEN 1
|
||||
|
||||
/* The maximum number of people who can talk at once */
|
||||
#define CHAT_MAXPEOPLE 10
|
||||
@@ -20,7 +20,6 @@ extern SDL_Point mouse_pos;
|
||||
extern int state;
|
||||
|
||||
void start_battle();
|
||||
void show_options();
|
||||
|
||||
#define GRAB_NEW 2
|
||||
#define GRAB_OLD 1
|
||||
|
||||
@@ -2,12 +2,17 @@
|
||||
#ifndef __my_net_h__
|
||||
#define __my_net_h__
|
||||
|
||||
#include <SDL_net.h>
|
||||
#include <game.h>
|
||||
|
||||
|
||||
#define PORT 36911
|
||||
|
||||
#define SERVER "localhost"
|
||||
|
||||
#define PACKSZ 1024
|
||||
|
||||
|
||||
enum pack_type{
|
||||
G_STATE, S_STATE, HOSTS_REQ, NEW_HOST, JOIN_REQ, U_NAME
|
||||
};
|
||||
@@ -17,32 +22,18 @@ typedef struct packet{
|
||||
char payload[PACKSZ - sizeof(enum pack_type)];
|
||||
} packet;
|
||||
|
||||
|
||||
int read_to_buff(Uint32 *buff, Uint32 *src, Uint32 sz)
|
||||
typedef struct host_info
|
||||
{
|
||||
if(sz%32){
|
||||
puts("error size must be div by 32");
|
||||
return 0;
|
||||
}
|
||||
for(Uint32 i = 0; i < (sz >> 2); i += 1)
|
||||
{
|
||||
*(buff + i) = SDLNet_Read32(src + i);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
char name[MAX_NAMESZ];
|
||||
IPaddress ip;
|
||||
}host_info;
|
||||
|
||||
int write_to_buff(Uint32 *buff, Uint32 *src, Uint32 sz)
|
||||
{
|
||||
if(sz%32){
|
||||
puts("error size must be div by 32");
|
||||
return 0;
|
||||
}
|
||||
for(Uint32 i = 0; i < (sz >> 2); i += 1)
|
||||
{
|
||||
SDLNet_Write32(*(src + i), (buff + i));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int read_from_packet(Uint32 *buff, Uint32 *src, Uint32 sz);
|
||||
int write_for_sending(Uint32 *buff, Uint32 *src, Uint32 sz);
|
||||
|
||||
|
||||
int new_host(char l[MAX_NAMESZ]);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
22
include/options.h
Normal file
22
include/options.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//Troy Rosin
|
||||
|
||||
#ifndef __options_h__
|
||||
#define __options_h__
|
||||
|
||||
|
||||
//gameplay, video, audio, mainmenu, exit game
|
||||
#define NUM_OPTIONS 5
|
||||
|
||||
#define GP_OPT_SEL 0
|
||||
#define VID_OPT_SEL 1
|
||||
#define AUD_OPT_SEL 2
|
||||
#define MM_OPT_SEL 3
|
||||
#define EXT_OPT_SEL 4
|
||||
|
||||
void init_options();
|
||||
void render_options();
|
||||
|
||||
int get_sel_opt();
|
||||
void set_sel_opt(int);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user