Skip to content

Commit

Permalink
protocol: make client-index implicit
Browse files Browse the repository at this point in the history
This will enable us to unify the code in a later commit.

This is a protocol-breaking change, and means that matching editor
and player must be used.
  • Loading branch information
kusma committed Jan 25, 2011
1 parent 5bfd04f commit 687df08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 3 additions & 4 deletions editor/editor.cpp
Expand Up @@ -561,9 +561,9 @@ SOCKET clientConnect(SOCKET serverSocket, sockaddr_in *host)
return clientSocket;
}

size_t clientIndex;
void processCommand(NetworkSocket &sock)
{
size_t clientIndex = 0;
int strLen, serverIndex, newRow;
std::string trackName;
const sync_track *t;
Expand All @@ -572,9 +572,7 @@ void processCommand(NetworkSocket &sock)
switch (cmd) {
case GET_TRACK:
// read data
sock.recv((char *)&clientIndex, sizeof(int), 0);
sock.recv((char *)&strLen, sizeof(int), 0);
clientIndex = ntohl(clientIndex);
strLen = ntohl(strLen);
if (!sock.connected())
return;
Expand All @@ -591,7 +589,7 @@ void processCommand(NetworkSocket &sock)
int(document.createTrack(trackName));

// setup remap
document.clientRemap[serverIndex] = clientIndex;
document.clientRemap[serverIndex] = clientIndex++;

// send key-frames
t = document.tracks[serverIndex];
Expand Down Expand Up @@ -701,6 +699,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)temp);
document.clientSocket = NetworkSocket(clientSocket);
document.clientRemap.clear();
clientIndex = 0;
document.sendPauseCommand(true);
document.sendSetRowCommand(trackView->getEditRow());
guiConnected = true;
Expand Down
8 changes: 3 additions & 5 deletions sync/device.c
Expand Up @@ -157,15 +157,13 @@ void sync_save_tracks(const struct sync_device *d)
}
}

static int request_track_data(SOCKET sock, const char *name, uint32_t idx)
static int request_track_data(SOCKET sock, const char *name)
{
unsigned char cmd = GET_TRACK;
uint32_t name_len = htonl(strlen(name));
idx = htonl(idx);

/* send request data */
return xsend(sock, (char *)&cmd, 1, 0) ||
xsend(sock, (char *)&idx, sizeof(idx), 0) ||
xsend(sock, (char *)&name_len, sizeof(name_len), 0) ||
xsend(sock, name, (int)strlen(name), 0);
}
Expand Down Expand Up @@ -223,7 +221,7 @@ static int purge_and_rerequest(struct sync_device *d)
d->data.tracks[i]->keys = NULL;
d->data.tracks[i]->num_keys = 0;

if (request_track_data(d->sock, d->data.tracks[i]->name, i))
if (request_track_data(d->sock, d->data.tracks[i]->name))
return 1;
}
return 0;
Expand Down Expand Up @@ -318,7 +316,7 @@ const struct sync_track *sync_get_track(struct sync_device *d,
#if SYNC_PLAYER
load_track_data(t, sync_track_path(d->base, name));
#else
request_track_data(d->sock, name, idx);
request_track_data(d->sock, name);
#endif

return t;
Expand Down

0 comments on commit 687df08

Please sign in to comment.