More string cleanups
FossilOrigin-Name: 3e5cb10d19eb7d5dbe346bff2f443f7e112e88ef6e870a30c887083690b71a86
This commit is contained in:
parent
095af0a1e7
commit
02d0afa3c7
2 changed files with 57 additions and 44 deletions
|
@ -163,17 +163,18 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
|
||||||
// each texture slot can have multople texture frames, of which currently only
|
// each texture slot can have multople texture frames, of which currently only
|
||||||
// the first is used additional frames can be used for various shaders
|
// the first is used additional frames can be used for various shaders
|
||||||
|
|
||||||
const int MAXTEX = 1000;
|
static const int MAXTEX = 1000;
|
||||||
int texx[MAXTEX]; // ( loaded texture ) -> ( name, size )
|
static int texx[MAXTEX]; // ( loaded texture ) -> ( name, size )
|
||||||
int texy[MAXTEX];
|
static int texy[MAXTEX];
|
||||||
string texname[MAXTEX];
|
static OFString *texname[MAXTEX];
|
||||||
int curtex = 0;
|
static int curtex = 0;
|
||||||
const int FIRSTTEX = 1000; // opengl id = loaded id + FIRSTTEX
|
static const int FIRSTTEX = 1000; // opengl id = loaded id + FIRSTTEX
|
||||||
// std 1+, sky 14+, mdls 20+
|
// std 1+, sky 14+, mdls 20+
|
||||||
|
|
||||||
const int MAXFRAMES = 2; // increase to allow more complex shader defs
|
static const int MAXFRAMES = 2; // increase to allow more complex shader defs
|
||||||
int mapping[256][MAXFRAMES]; // ( cube texture, frame ) -> ( opengl id, name )
|
static int mapping[256]
|
||||||
string mapname[256][MAXFRAMES];
|
[MAXFRAMES]; // ( cube texture, frame ) -> ( opengl id, name )
|
||||||
|
static OFString *mapname[256][MAXFRAMES];
|
||||||
|
|
||||||
void
|
void
|
||||||
purgetextures()
|
purgetextures()
|
||||||
|
@ -198,8 +199,7 @@ texture(OFString *aframe, OFString *name)
|
||||||
if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
|
if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES)
|
||||||
return;
|
return;
|
||||||
mapping[num][frame] = 1;
|
mapping[num][frame] = 1;
|
||||||
char *n = mapname[num][frame];
|
mapname[num][frame] = name;
|
||||||
strcpy_s(n, name.UTF8String);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
COMMAND(texture, ARG_2STR)
|
COMMAND(texture, ARG_2STR)
|
||||||
|
@ -222,7 +222,7 @@ lookuptexture(int tex, int *xs, int *ys)
|
||||||
|
|
||||||
loopi(curtex) // lazily happens once per "texture" command, basically
|
loopi(curtex) // lazily happens once per "texture" command, basically
|
||||||
{
|
{
|
||||||
if (strcmp(mapname[tex][frame], texname[i]) == 0) {
|
if ([mapname[tex][frame] isEqual:texname[i]]) {
|
||||||
mapping[tex][frame] = tid = i + FIRSTTEX;
|
mapping[tex][frame] = tid = i + FIRSTTEX;
|
||||||
*xs = texx[i];
|
*xs = texx[i];
|
||||||
*ys = texy[i];
|
*ys = texy[i];
|
||||||
|
@ -234,11 +234,11 @@ lookuptexture(int tex, int *xs, int *ys)
|
||||||
fatal(@"loaded too many textures");
|
fatal(@"loaded too many textures");
|
||||||
|
|
||||||
int tnum = curtex + FIRSTTEX;
|
int tnum = curtex + FIRSTTEX;
|
||||||
strcpy_s(texname[curtex], mapname[tex][frame]);
|
texname[curtex] = mapname[tex][frame];
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
OFString *path =
|
OFString *path =
|
||||||
[OFString stringWithFormat:@"packages/%s", texname[curtex]];
|
[OFString stringWithFormat:@"packages/%@", texname[curtex]];
|
||||||
|
|
||||||
if (installtex(tnum,
|
if (installtex(tnum,
|
||||||
[Cube.sharedInstance.gameDataIRI
|
[Cube.sharedInstance.gameDataIRI
|
||||||
|
|
|
@ -2,14 +2,17 @@
|
||||||
|
|
||||||
#include "cube.h"
|
#include "cube.h"
|
||||||
|
|
||||||
ENetSocket mssock = ENET_SOCKET_NULL;
|
static ENetSocket mssock = ENET_SOCKET_NULL;
|
||||||
|
|
||||||
void
|
static void
|
||||||
httpgetsend(ENetAddress &ad, char *hostname, char *req, char *ref, char *agent)
|
httpgetsend(ENetAddress &ad, OFString *hostname, OFString *req, OFString *ref,
|
||||||
|
OFString *agent)
|
||||||
{
|
{
|
||||||
if (ad.host == ENET_HOST_ANY) {
|
if (ad.host == ENET_HOST_ANY) {
|
||||||
printf("looking up %s...\n", hostname);
|
[OFStdOut writeFormat:@"looking up %@...\n", hostname];
|
||||||
enet_address_set_host(&ad, hostname);
|
@autoreleasepool {
|
||||||
|
enet_address_set_host(&ad, hostname.UTF8String);
|
||||||
|
}
|
||||||
if (ad.host == ENET_HOST_ANY)
|
if (ad.host == ENET_HOST_ANY)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,16 +28,18 @@ httpgetsend(ENetAddress &ad, char *hostname, char *req, char *ref, char *agent)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ENetBuffer buf;
|
ENetBuffer buf;
|
||||||
sprintf_sd(httpget)(
|
OFString *httpget = [OFString stringWithFormat:@"GET %@ HTTP/1.0\n"
|
||||||
"GET %s HTTP/1.0\nHost: %s\nReferer: %s\nUser-Agent: %s\n\n", req,
|
@"Host: %@\n"
|
||||||
hostname, ref, agent);
|
@"Referer: %@\n"
|
||||||
buf.data = httpget;
|
@"User-Agent: %@\n\n",
|
||||||
buf.dataLength = strlen((char *)buf.data);
|
req, hostname, ref, agent];
|
||||||
printf("sending request to %s...\n", hostname);
|
buf.data = (void *)httpget.UTF8String;
|
||||||
|
buf.dataLength = httpget.UTF8StringLength;
|
||||||
|
[OFStdOut writeFormat:@"sending request to %@...\n", hostname];
|
||||||
enet_socket_send(mssock, NULL, &buf, 1);
|
enet_socket_send(mssock, NULL, &buf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
httpgetrecieve(ENetBuffer &buf)
|
httpgetrecieve(ENetBuffer &buf)
|
||||||
{
|
{
|
||||||
if (mssock == ENET_SOCKET_NULL)
|
if (mssock == ENET_SOCKET_NULL)
|
||||||
|
@ -53,7 +58,7 @@ httpgetrecieve(ENetBuffer &buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uchar *
|
static uchar *
|
||||||
stripheader(uchar *b)
|
stripheader(uchar *b)
|
||||||
{
|
{
|
||||||
char *s = strstr((char *)b, "\n\r\n");
|
char *s = strstr((char *)b, "\n\r\n");
|
||||||
|
@ -62,21 +67,25 @@ stripheader(uchar *b)
|
||||||
return s ? (uchar *)s : b;
|
return s ? (uchar *)s : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetAddress masterserver = { ENET_HOST_ANY, 80 };
|
static ENetAddress masterserver = { ENET_HOST_ANY, 80 };
|
||||||
int updmaster = 0;
|
static int updmaster = 0;
|
||||||
string masterbase;
|
static OFString *masterbase;
|
||||||
string masterpath;
|
static OFString *masterpath;
|
||||||
uchar masterrep[MAXTRANS];
|
static uchar masterrep[MAXTRANS];
|
||||||
ENetBuffer masterb;
|
static ENetBuffer masterb;
|
||||||
|
|
||||||
void
|
static void
|
||||||
updatemasterserver(int seconds)
|
updatemasterserver(int seconds)
|
||||||
{
|
{
|
||||||
// send alive signal to masterserver every hour of uptime
|
// send alive signal to masterserver every hour of uptime
|
||||||
if (seconds > updmaster) {
|
if (seconds > updmaster) {
|
||||||
sprintf_sd(path)("%sregister.do?action=add", masterpath);
|
@autoreleasepool {
|
||||||
httpgetsend(masterserver, masterbase, path, "cubeserver",
|
OFString *path = [OFString
|
||||||
"Cube Server");
|
stringWithFormat:@"%@register.do?action=add",
|
||||||
|
masterpath];
|
||||||
|
httpgetsend(masterserver, masterbase, path,
|
||||||
|
@"cubeserver", @"Cube Server");
|
||||||
|
}
|
||||||
masterrep[0] = 0;
|
masterrep[0] = 0;
|
||||||
masterb.data = masterrep;
|
masterb.data = masterrep;
|
||||||
masterb.dataLength = MAXTRANS - 1;
|
masterb.dataLength = MAXTRANS - 1;
|
||||||
|
@ -84,7 +93,7 @@ updatemasterserver(int seconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
checkmasterreply()
|
checkmasterreply()
|
||||||
{
|
{
|
||||||
bool busy = mssock != ENET_SOCKET_NULL;
|
bool busy = mssock != ENET_SOCKET_NULL;
|
||||||
|
@ -96,9 +105,12 @@ checkmasterreply()
|
||||||
uchar *
|
uchar *
|
||||||
retrieveservers(uchar *buf, int buflen)
|
retrieveservers(uchar *buf, int buflen)
|
||||||
{
|
{
|
||||||
sprintf_sd(path)("%sretrieve.do?item=list", masterpath);
|
@autoreleasepool {
|
||||||
httpgetsend(
|
OFString *path = [OFString
|
||||||
masterserver, masterbase, path, "cubeserver", "Cube Server");
|
stringWithFormat:@"%@retrieve.do?item=list", masterpath];
|
||||||
|
httpgetsend(masterserver, masterbase, path, @"cubeserver",
|
||||||
|
@"Cube Server");
|
||||||
|
}
|
||||||
ENetBuffer eb;
|
ENetBuffer eb;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
eb.data = buf;
|
eb.data = buf;
|
||||||
|
@ -108,7 +120,7 @@ retrieveservers(uchar *buf, int buflen)
|
||||||
return stripheader(buf);
|
return stripheader(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetSocket pongsock = ENET_SOCKET_NULL;
|
static ENetSocket pongsock = ENET_SOCKET_NULL;
|
||||||
static OFString *serverdesc;
|
static OFString *serverdesc;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -153,8 +165,9 @@ servermsinit(OFString *master_, OFString *sdesc, bool listen)
|
||||||
const char *mid = strstr(master, "/");
|
const char *mid = strstr(master, "/");
|
||||||
if (!mid)
|
if (!mid)
|
||||||
mid = master;
|
mid = master;
|
||||||
strcpy_s(masterpath, mid);
|
masterpath = @(mid);
|
||||||
strn0cpy(masterbase, master, mid - master + 1);
|
masterbase = [[OFString alloc] initWithUTF8String:master
|
||||||
|
length:mid - master];
|
||||||
serverdesc = sdesc;
|
serverdesc = sdesc;
|
||||||
|
|
||||||
if (listen) {
|
if (listen) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue