Fix server-client communication

Regression was introduced by 08a2d53eb4.
This commit is contained in:
Přemysl Eric Janouch 2014-11-30 17:24:35 +01:00
parent 362fa366a7
commit 3e9bc6cee7
1 changed files with 19 additions and 11 deletions

View File

@ -495,16 +495,8 @@ make_place_for_point (app_context_t *app, int x, int y)
}
static void
draw_point (app_context_t *app, int x, int y, uint8_t color)
draw_point_internal (app_context_t *app, int x, int y, uint8_t color)
{
// We don't actually draw anything immediately in client mode,
// instead we wait for confirmation from the server
if (app->mode == NETWORK_MODE_CLIENT)
{
send_draw_point_request (app, x, y, color);
return;
}
make_place_for_point (app, x, y);
BITMAP_PIXEL (app, x - app->bitmap_x, y - app->bitmap_y) = color;
@ -517,8 +509,22 @@ draw_point (app_context_t *app, int x, int y, uint8_t color)
addch (app->palette[color]);
refresh ();
}
}
// Broadcast the clients about the event
static void
draw_point (app_context_t *app, int x, int y, uint8_t color)
{
// We don't actually draw anything immediately in client mode,
// instead we wait for confirmation from the server
if (app->mode == NETWORK_MODE_CLIENT)
{
send_draw_point_request (app, x, y, color);
return;
}
draw_point_internal (app, x, y, color);
// Broadcast clients about the event
if (app->mode == NETWORK_MODE_SERVER)
for (client_t *iter = app->clients; iter; iter = iter->next)
send_draw_point_response (iter, x, y, color);
@ -1119,7 +1125,9 @@ on_server_put_point (app_context_t *app, struct msg_unpacker *unpacker)
|| !msg_unpacker_u8 (unpacker, &color))
return false; // Not enough data
draw_point (app, x, y, color);
// Either a confirmation of our own request, or an event notification;
// let's just put the pixel in place without further ado
draw_point_internal (app, x, y, color);
return true;
}