Skip to content
Snippets Groups Projects
Select Git revision
  • better-distance-math
  • next default protected
  • movie
  • softcode-info
  • master protected
  • acs
  • spriteinfo-refactor
  • clipmidtex
  • custom-map-names
  • nogravity-trampolines
  • 2214-pre4
  • 2214-pre3
  • just-in-case
  • fix-opengl-parameter-crash
  • 2214-pre2
  • 2214-pre1
  • delfile2
  • cleanupmusic
  • gametype-refactor-1
  • extra-textures
  • SRB2_release_2.2.15
  • SRB2_release_2.2.13
  • SRB2_release_2.2.12
  • SRB2_release_2.2.11
  • SRB2_release_2.2.10
  • SRB2_release_2.2.9
  • SRB2_release_2.2.8
  • SRB2_release_2.2.7
  • SRB2_release_2.2.6
  • SRB2_release_2.2.5
  • SRB2_release_2.2.4
  • SRB2_release_2.2.3
  • SRB2_release_2.2.2
  • SRB2_release_2.2.1
  • SRB2_release_2.2.0
  • SRB2_release_2.1.25
  • SRB2_release_2.1.24
  • SRB2_release_2.1.23
  • SRB2_release_2.1.22
  • SRB2_release_2.1.21
40 results

client.cpp

Blame
  • Alam Ed Arias's avatar
    Alam Ed Arias authored and Alam Arias committed
    b93cb1b6
    History
    client.cpp 3.25 KiB
    // Emacs style mode select   -*- C++ -*-
    //-----------------------------------------------------------------------------
    //
    // Copyright (C) 2000 by DooM Legacy Team.
    //
    // This program is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public License
    // as published by the Free Software Foundation; either version 2
    // of the License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    //
    //-----------------------------------------------------------------------------
    
    #include <time.h>
    #include <string.h>
    #include "ipcs.h"
    #include "common.h"
    
    //=============================================================================
    
    static CClientSocket client_socket;
    //static msg_t msg;
    FILE *logfile;
    
    //=============================================================================
    
    static msg_t *getData(int argc, char *argv[])
    {
    	static msg_t msg;
    	msg_server_t *info = (msg_server_t *)msg.buffer;
    
    #if defined (_WIN32)
    	strcpy(info->header.buffer, "");
    #else
    	strcpy(info->header.buffer, getpass("Enter password: "));
    #endif
    
    	// default values if one of the param is not entered
    	strcpy(info->ip,       "88.86.106.169");
    	strcpy(info->port,     "5029");
    	strcpy(info->name,     "Cueball's Dedicated Server");
    	strcpy(info->version,  "1.09.4");
    	msg.type = ADD_PSERVER_MSG;
    	msg.length = sizeof (msg_server_t);
    
    	for (int i = 0; i < argc; i++)
    	{
    		// first: extra parameters (must be after all -param)
    		if (!strcasecmp(argv[i], "get"))
    		{
    			msg.type = GET_SERVER_MSG;
    			msg.length = 0;
    		}
    		else if (!strcasecmp(argv[i], "log"))
    		{
    			msg.type = GET_LOGFILE_MSG;
    			msg.length = sizeof (msg_server_t);
    		}
    		else if (!strcasecmp(argv[i], "erase"))
    		{
    			msg.type = ERASE_LOGFILE_MSG;
    			msg.length = sizeof (msg_server_t);
    		}
    		else if (!strcasecmp(argv[i], "remove"))
    		{
    			msg.type = REMOVE_PSERVER_MSG;
    			msg.length = sizeof (msg_server_t);
    		}
    
    		if (i >= argc-1)
    			continue;
    
    		// second: parameter requiring extra parameters
    		if (strcasecmp(argv[i], "-ip") == 0)
    			strcpy(info->ip, argv[i+1]);
    		else if (strcasecmp(argv[i], "-port") == 0)
    			strcpy(info->port, argv[i+1]);
    		else if (strcasecmp(argv[i], "-hostname") == 0)
    			strcpy(info->name, argv[i+1]);
    		else if (strcasecmp(argv[i], "-version") == 0)
    			strcpy(info->version, argv[i+1]);
    		else if (strcasecmp(argv[i], "-pass") == 0)
    			strcpy(info->header.buffer, argv[i+1]);
    	}
    	return &msg;
    }
    
    int main(int argc, char *argv[])
    {
    	if (argc == 2)
    	{
    		printf("encrypt: %s\n", pCrypt(argv[1], "04"));
    		return 0;
    	}
    	else if (argc > 2)
    	{
    		if (client_socket.connect(argv[1], argv[2]) < 0)
    		{
    			conPrintf(RED, "Connect failed.\n");
    			return -1;
    		}
    
    		msg_t *msg = getData(argc, argv);
    
    		if (client_socket.write(msg) < 0)
    		{
    			dbgPrintf(RED, "Write failed.\n");
    			return -1;
    		}
    
    		switch (ntohl(msg->type))
    		{
    		case GET_SERVER_MSG:
    		case GET_LOGFILE_MSG:
    			while (client_socket.read(msg) >= 0)
    			{
    				if (ntohl(msg->length) == 0)
    					break;
    				printf("%s", msg->buffer);
    			}
    			break;
    
    		case REMOVE_PSERVER_MSG:
    		default:
    			break;
    		}
    	}
    	return 0;
    }