[Freeciv-Dev] (PR#11122) remove is_server checks in packet code
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=11122 >
> [jdorje - Sun Nov 21 04:58:43 2004]:
>
> This patch adds a new is_server field to the connection struct. This
> field is set at server and client and used in place of the global
> is_server value.
Here's a new patch. Mike requested that the log messages in the
packets_gen code be changed.
Index: client/clinet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v
retrieving revision 1.107
diff -u -r1.107 clinet.c
--- client/clinet.c 14 Nov 2004 23:09:59 -0000 1.107
+++ client/clinet.c 22 Nov 2004 22:29:41 -0000
@@ -209,6 +209,7 @@
}
connection_common_init(&aconnection);
+ aconnection.is_server = FALSE;
aconnection.client.last_request_id_used = 0;
aconnection.client.last_processed_request_id_seen = 0;
aconnection.client.request_id_of_currently_handled_packet = 0;
Index: common/connection.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/connection.h,v
retrieving revision 1.37
diff -u -r1.37 connection.h
--- common/connection.h 12 Sep 2004 21:44:10 -0000 1.37
+++ common/connection.h 22 Nov 2004 22:29:41 -0000
@@ -147,6 +147,8 @@
void (*notify_of_writable_data) (struct connection * pc,
bool data_available_and_socket_full);
+ /* Determines whether client or server behavior should be used. */
+ bool is_server;
struct {
/*
* Increases for every packet send to the server.
Index: common/generate_packets.py
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/generate_packets.py,v
retrieving revision 1.14
diff -u -r1.14 generate_packets.py
--- common/generate_packets.py 3 Sep 2004 04:22:37 -0000 1.14
+++ common/generate_packets.py 22 Nov 2004 22:29:42 -0000
@@ -1101,13 +1101,13 @@
only_client=len(self.dirs)==1 and self.dirs[0]=="sc"
only_server=len(self.dirs)==1 and self.dirs[0]=="cs"
if only_client:
- restrict=''' if(is_server) {
- freelog(LOG_ERROR, "Receiving %(name)s at the server.");
+ restrict=''' if (pc->is_server) {
+ freelog(LOG_ERROR, "Receiving invalid packet %(name)s.");
}
'''%self.get_dict(vars())
elif only_server:
- restrict=''' if(!is_server) {
- freelog(LOG_ERROR, "Receiving %(name)s at the client.");
+ restrict=''' if (!pc->is_server) {
+ freelog(LOG_ERROR, "Receiving invalid packet %(name)s.");
}
'''%self.get_dict(vars())
else:
@@ -1137,13 +1137,13 @@
only_client=len(self.dirs)==1 and self.dirs[0]=="cs"
only_server=len(self.dirs)==1 and self.dirs[0]=="sc"
if only_client:
- restrict=''' if(is_server) {
- freelog(LOG_ERROR, "Sending %(name)s from the server.");
+ restrict=''' if (pc->is_server) {
+ freelog(LOG_ERROR, "Sending invalid packet %(name)s.");
}
'''%self.get_dict(vars())
elif only_server:
- restrict=''' if(!is_server) {
- freelog(LOG_ERROR, "Sending %(name)s from the client.");
+ restrict=''' if (!pc->is_server) {
+ freelog(LOG_ERROR, "Sending invalid packet %(name)s.");
}
'''%self.get_dict(vars())
else:
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.271
diff -u -r1.271 packets.c
--- common/packets.c 16 Sep 2004 03:20:13 -0000 1.271
+++ common/packets.c 22 Nov 2004 22:29:43 -0000
@@ -93,8 +93,7 @@
***********************************************************************/
/**************************************************************************
-It returns the request id of the outgoing packet or 0 if the packet
-was no request (i.e. server sends packet).
+ It returns the request id of the outgoing packet (or 0 if pc->is_server).
**************************************************************************/
int send_packet_data(struct connection *pc, unsigned char *data, int len)
{
@@ -104,7 +103,7 @@
freelog(BASIC_PACKET_LOG_LEVEL, "sending packet type=%s(%d) len=%d",
get_packet_name(data[2]), data[2], len);
- if (!is_server) {
+ if (!pc->is_server) {
pc->client.last_request_id_used =
get_next_request_id(pc->client.last_request_id_used);
result = pc->client.last_request_id_used;
@@ -454,8 +453,7 @@
packets_stats[packet_type].size += size;
packet_counter++;
- if ((is_server && (packet_counter % 10 == 0))
- || (!is_server && (packet_counter % 1000 == 0))) {
+ if (packet_counter % 100 == 0) {
int i, sum = 0;
freelog(LOG_NORMAL, "Received packets:");
Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.127
diff -u -r1.127 sernet.c
--- server/sernet.c 16 Nov 2004 17:56:54 -0000 1.127
+++ server/sernet.c 22 Nov 2004 22:29:44 -0000
@@ -756,6 +756,7 @@
pconn->access_level = access_level_for_next_connection();
pconn->delayed_disconnect = FALSE;
pconn->notify_of_writable_data = NULL;
+ pconn->is_server = TRUE;
pconn->server.currently_processed_request_id = 0;
pconn->server.last_request_id_seen = 0;
pconn->server.authentication_tries = 0;
|
|