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