changeset 3:2607e160df57

Spawn bots for each pid
author Josef "Jeff" Sipek <jeffpc@optonline.net>
date Fri, 26 Aug 2005 14:48:20 -0500
parents b91d9b779dd6
children 8fdd344cdc06
files main.c
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Fri Aug 26 14:31:29 2005 -0500
+++ b/main.c	Fri Aug 26 14:48:20 2005 -0500
@@ -38,6 +38,7 @@
 	char *ibuf, *obuf;
 	struct proc *bots;
 	int pid, pids;
+	int obuf_preflen;
 	int ret;
 	
 	int owner = CONFIG_OWNER;
@@ -75,6 +76,8 @@
 	init_outbuf(obuf);
 	memset(bots, 0, sizeof(struct proc)*MAX_PID);
 	
+	obuf_preflen = strlen(obuf);
+	
 	for(pid=0, pids=0; pid < MAX_PID; pid++) {
 		ret = kill(pid,0);
 		
@@ -88,12 +91,18 @@
 			bots[pid].ignore = (pid==getpid());
 			snprintf(bots[pid].comm, BOT_NAME_LEN, "bot%d", pid);
 			
+			snprintf(obuf + obuf_preflen, BUF_LEN-obuf_preflen, "bot addbot %s %d %d",
+				bots[pid].comm,
+				1 /* always on this team */,
+				0 /* always a soldier */);
+			printf("bot: %s\n", obuf);
+			write(sockfd, obuf, strlen(obuf));
+			usleep(500000);
 			pids++;
 		}
 	}
 	printf("Total %d pids found\n", pids);
 	
-	write(sockfd, obuf, strlen(obuf));
 	while(1) {
 		ret = read(sockfd, ibuf, BUF_LEN-1);
 		printf("%d bytes: %s\n",ret, ibuf);