74b1de775402f2f9a9e3296248bcf8bd2622e2df
[dragonfly.git] / games / hunt / hunt / connect.c
1 /*
2  * Copyright (c) 1983-2003, Regents of the University of California.
3  * All rights reserved.
4  * 
5  * Redistribution and use in source and binary forms, with or without 
6  * modification, are permitted provided that the following conditions are 
7  * met:
8  * 
9  * + Redistributions of source code must retain the above copyright 
10  *   notice, this list of conditions and the following disclaimer.
11  * + Redistributions in binary form must reproduce the above copyright 
12  *   notice, this list of conditions and the following disclaimer in the 
13  *   documentation and/or other materials provided with the distribution.
14  * + Neither the name of the University of California, San Francisco nor 
15  *   the names of its contributors may be used to endorse or promote 
16  *   products derived from this software without specific prior written 
17  *   permission.
18  * 
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $OpenBSD: connect.c,v 1.6 2003/06/11 08:45:24 pjanzen Exp $
32  * $NetBSD: connect.c,v 1.3 1997/10/11 08:13:40 lukem Exp $
33  * $DragonFly: src/games/hunt/hunt/connect.c,v 1.1 2008/09/02 21:50:20 dillon Exp $
34  */
35
36 #include <sys/types.h>
37 #include <arpa/inet.h>
38 #include <signal.h>
39 #include <unistd.h>
40 #include <string.h>
41
42 #include "hunt.h"
43 #include "client.h"
44
45 void
46 do_connect(name, team, enter_status)
47         char *          name;
48         u_int8_t        team;
49         u_int32_t       enter_status;
50 {
51         u_int32_t       uid;
52         u_int32_t       mode;
53         const char *    Ttyname;
54         char            buf[NAMELEN];
55
56         if (Send_message != NULL)
57                 mode = C_MESSAGE;
58         else if (Am_monitor)
59                 mode = C_MONITOR;
60         else
61                 mode = C_PLAYER;
62
63         Ttyname = ttyname(STDOUT_FILENO);
64         if (Ttyname == NULL)
65                 Ttyname = "not a tty";
66         memset(buf, '\0', sizeof buf);
67         (void) strlcpy(buf, Ttyname, sizeof buf);
68
69         uid = htonl(getuid());
70         enter_status = htonl(enter_status);
71         mode = htonl(mode);
72
73         (void) write(Socket, &uid, sizeof uid);
74         (void) write(Socket, name, NAMELEN);
75         (void) write(Socket, &team, sizeof team);
76         (void) write(Socket, &enter_status, sizeof enter_status);
77         (void) write(Socket, buf, NAMELEN);
78         (void) write(Socket, &mode, sizeof mode);
79 }