project_files/frontlib/net/netconn_send.c
changeset 7314 6171f0bad318
parent 7275 15f722e0b96f
child 7316 f7b49b2c5d84
equal deleted inserted replaced
7312:d1db8aaa8edc 7314:6171f0bad318
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU General Public License
       
     7  * as published by the Free Software Foundation; either version 2
       
     8  * of the License, or (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    18  */
       
    19 
     1 #include "netconn_internal.h"
    20 #include "netconn_internal.h"
     2 
    21 
     3 #include "../util/logging.h"
    22 #include "../util/logging.h"
     4 #include "../util/util.h"
    23 #include "../util/util.h"
     5 #include "../util/buffer.h"
    24 #include "../util/buffer.h"
    66 		free(tmpName);
    85 		free(tmpName);
    67 	}
    86 	}
    68 	return result;
    87 	return result;
    69 }
    88 }
    70 
    89 
    71 int flib_netconn_send_password(flib_netconn *conn, const char *latin1Passwd) {
    90 int flib_netconn_send_password(flib_netconn *conn, const char *passwd) {
    72 	int result = -1;
    91 	int result = -1;
    73 	if(!log_badparams_if(!conn || !latin1Passwd)) {
    92 	if(!log_badparams_if(!conn || !passwd)) {
    74 		md5_state_t md5state;
    93 		md5_state_t md5state;
    75 		uint8_t md5bytes[16];
    94 		uint8_t md5bytes[16];
    76 		char md5hex[33];
    95 		char md5hex[33];
    77 		md5_init(&md5state);
    96 		md5_init(&md5state);
    78 		md5_append(&md5state, (unsigned char*)latin1Passwd, strlen(latin1Passwd));
    97 		md5_append(&md5state, (unsigned char*)passwd, strlen(passwd));
    79 		md5_finish(&md5state, md5bytes);
    98 		md5_finish(&md5state, md5bytes);
    80 		for(int i=0;i<sizeof(md5bytes); i++) {
    99 		for(int i=0;i<sizeof(md5bytes); i++) {
    81 			// Needs to be lowercase - server checks case sensitive
   100 			// Needs to be lowercase - server checks case sensitive
    82 			snprintf(md5hex+i*2, 3, "%02x", (unsigned)md5bytes[i]);
   101 			snprintf(md5hex+i*2, 3, "%02x", (unsigned)md5bytes[i]);
    83 		}
   102 		}
   104 
   123 
   105 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName) {
   124 int flib_netconn_send_renameRoom(flib_netconn *conn, const char *roomName) {
   106 	return sendStr(conn, "ROOM_NAME", roomName);
   125 	return sendStr(conn, "ROOM_NAME", roomName);
   107 }
   126 }
   108 
   127 
   109 int flib_netconn_send_leaveRoom(flib_netconn *conn) {
   128 int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *str) {
   110 	if(flib_netconn_is_in_room_context(conn) && !sendVoid(conn, "PART")) {
   129 	int result = -1;
   111 		netconn_leaveRoom(conn);
   130 	if(flib_netconn_is_in_room_context(conn)) {
   112 		return 0;
   131 		int result = (str && *str) ? sendStr(conn, "PART", str) : sendVoid(conn, "PART");
   113 	}
   132 		if(!result) {
   114 	return -1;
   133 			netconn_leaveRoom(conn);
       
   134 		}
       
   135 	}
       
   136 	return result;
   115 }
   137 }
   116 
   138 
   117 int flib_netconn_send_toggleReady(flib_netconn *conn) {
   139 int flib_netconn_send_toggleReady(flib_netconn *conn) {
   118 	return sendVoid(conn, "TOGGLE_READY");
   140 	return sendVoid(conn, "TOGGLE_READY");
   119 }
   141 }