fe7fe4bd719ae77c82e7a6e7418034c4d191edd0
[reactos.git] / reactos / apps / utils / net / tcpsvcs / qotd.c
1 #include <stdio.h>
2 #include <winsock2.h>
3 #include <tchar.h>
4 #include <time.h>
5 #include "tcpsvcs.h"
6
7 //these need putting in an RC file.
8 TCHAR Quotes[][MAX_QUOTE_BUF] =
9 {
10 _T("\"I have a penchant for mischief, property damage, stalking and cheesecake, of course\"\r\n - kjk hyperion"),
11 _T("\"Wow! I fixed a setmenu bug.\" - jimtabor"),
12 _T("\"if the code is broken though, your free to call it ur own\"\r\n - Alex Ionescu"),
13 _T("\"i don't know about any bug; none exist; ReactOS is prefect\"\r\n - filip2307"),
14 _T("\"if you were kernel code, cutler would rewrite you.\"\r\n - Alex Ionescu"),
15 _T("\"Looks like Hartmut is cleaning out his WC. working copy, that is\"\r\n - WaxDragon")
16 _T("\"don't question it ... it's clearly an optimization\"\r\n - arty")
17 };
18
19 DWORD WINAPI QotdHandler(VOID* Sock_)
20 {
21 DWORD Retval = 0;
22 SOCKET Sock;
23 INT NumOfQuotes;
24 INT QuoteToPrint;
25
26 Sock = (SOCKET)Sock_;
27 NumOfQuotes = sizeof(Quotes) / MAX_QUOTE_BUF;
28
29 /* randomise the quote */
30 srand((unsigned int) time(0));
31 QuoteToPrint = rand() % NumOfQuotes;
32
33 SendQuote(Sock, Quotes[QuoteToPrint]);
34
35 _tprintf(_T("Shutting connection down...\n"));
36 if (ShutdownConnection(Sock, FALSE))
37 _tprintf(_T("Connection is down.\n"));
38 else
39 {
40 _tprintf(_T("Connection shutdown failed\n"));
41 Retval = 3;
42 }
43 _tprintf(_T("Terminating thread\n"));
44 ExitThread(0);
45
46 return Retval;
47 }
48
49
50 BOOL SendQuote(SOCKET Sock, TCHAR* Quote)
51 {
52 INT StringSize;
53 INT RetVal;
54
55 StringSize = strlen(Quote);
56 RetVal = send(Sock, Quote, sizeof(TCHAR) * StringSize, 0);
57
58 if (RetVal == SOCKET_ERROR)
59 return FALSE;
60
61 _tprintf(("Connection closed by peer.\n"));
62 return TRUE;
63 }