ref: 48531e4fd34f0f14b9fec0e844603d15cd3e184b
parent: 02dabfd303e35c1508959b17b46d07bcd3d3adbc
author: mkf <mkf@cloud9p.org>
date: Tue Jun 4 14:58:18 EDT 2024
netclient: add himsg
--- a/netclient.c
+++ b/netclient.c
@@ -15,11 +15,30 @@
int srvfd;
+char *pnick;
+int pside;
+int pgame;
+int popts;
+
static char*
+himsg(char *name, int game, int side, int opts)
+{
+ char *msg;
+
+ dprint("himsg(%s, %d, %d, %d)\n", name, game, side, opts);
+ if(side > PRandom)
+ return nil;
+
+ msg = (char*)emalloc(32);
+ sprint(msg, "%s %d %d %d\n", name, game, side, opts);
+ return msg;
+}
+
+static char*
movemsg(int dir)
{
char *d, *msg;
-
+
d = dirtostr(dir);
if(d == nil)
return nil;
@@ -43,6 +62,26 @@
}
int
+nethi(char *name, int game, int side, int opts)
+{
+ int len;
+ char *msg;
+
+ msg = himsg(name, game, side, opts);
+ if(msg == nil)
+ return Err;
+
+ len = strlen(msg);
+ if(write(srvfd, msg, len) < len)
+ sysfatal("nethi(): half written?");
+
+ /* otherwise client wont read socket to confirm */
+ waitbit = 1;
+ free(msg);
+ return Ok;
+}
+
+int
netmove(int dir)
{
int len;
@@ -248,6 +287,9 @@
char *s;
msg = malloc(sizeof(Netmsg));
+ if(state == Connect)
+ nethi(pnick, pgame, pside, popts);
+
s = netread();
netproc(msg, s);
free(s);
--- a/netclient.h
+++ b/netclient.h
@@ -8,7 +8,12 @@
extern int srvfd;
+extern char *pnick;
+extern int pside;
+extern int pgame;
+extern int popts;
+
int netmove(int dir);
int netput(int x, int y);
char* netread(void);
-Netmsg* netmain(void);
\ No newline at end of file
+Netmsg* netmain(void);