Skip to content

Commit

Permalink
Upstream update: edit clipboard is now synchronized when a new player…
Browse files Browse the repository at this point in the history
… connects to a coop-edit
  • Loading branch information
greghaynes committed Jul 21, 2010
1 parent b0397df commit 64b1f5c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/engine/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@ void serverslice(bool dedicated, uint timeout) // main server update, called f
if(server::sendpackets()) enet_host_flush(serverhost);
}

void flushserver(bool force)
{
if(server::sendpackets(force) && serverhost) enet_host_flush(serverhost);
}

#ifndef STANDALONE
void localdisconnect(bool cleanup)
{
Expand Down
2 changes: 1 addition & 1 deletion src/fpsgame/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ enum
SV_PING, SV_PONG, SV_CLIENTPING,
SV_TIMEUP, SV_MAPRELOAD, SV_FORCEINTERMISSION,
SV_SERVMSG, SV_ITEMLIST, SV_RESUME,
SV_EDITMODE, SV_EDITENT, SV_EDITF, SV_EDITT, SV_EDITM, SV_FLIP, SV_COPY, SV_PASTE, SV_ROTATE, SV_REPLACE, SV_DELCUBE, SV_REMIP, SV_NEWMAP, SV_GETMAP, SV_SENDMAP, SV_EDITVAR,
SV_EDITMODE, SV_EDITENT, SV_EDITF, SV_EDITT, SV_EDITM, SV_FLIP, SV_COPY, SV_PASTE, SV_ROTATE, SV_REPLACE, SV_DELCUBE, SV_REMIP, SV_NEWMAP, SV_GETMAP, SV_SENDMAP, SV_CLIPBOARD, SV_EDITVAR,
SV_MASTERMODE, SV_KICK, SV_CLEARBANS, SV_CURRENTMASTER, SV_SPECTATOR, SV_SETMASTER, SV_SETTEAM,
SV_BASES, SV_BASEINFO, SV_BASESCORE, SV_REPAMMO, SV_BASEREGEN, SV_ANNOUNCE,
SV_LISTDEMOS, SV_SENDDEMOLIST, SV_GETDEMO, SV_SENDDEMO,
Expand Down
56 changes: 53 additions & 3 deletions src/fpsgame/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,11 @@ namespace server
}
}

bool sendpackets()
bool sendpackets(bool force)
{
if(clients.empty() || (!hasnonlocalclients() && !demorecord)) return false;
enet_uint32 curtime = enet_time_get()-lastsend;
if(curtime<33) return false;
if(curtime<33 && !force) return false;
bool flush = buildworldstate();
lastsend += curtime - (curtime%33);
return flush;
Expand Down Expand Up @@ -1592,6 +1592,21 @@ namespace server
SbPy::triggerEventInt("player_uploaded_map", sender);
}

void sendclipboard(clientinfo *ci)
{
if(!ci->lastclipboard || !ci->clipboard) return;
bool flushed = false;
loopv(clients)
{
clientinfo &e = *clients[i];
if(e.clientnum != ci->clientnum && e.connectmillis >= ci->lastclipboard)
{
if(!flushed) { flushserver(true); flushed = true; }
sendpacket(e.clientnum, 1, ci->clipboard);
}
}
}

void parsepacket(int sender, int chan, packetbuf &p) // has to parse exactly each byte of the packet
{
if(sender<0) return;
Expand Down Expand Up @@ -1630,6 +1645,7 @@ namespace server
clients.add(ci);

ci->connected = true;
ci->connectmillis = totalmillis;
if(mastermode>=MM_LOCKED) ci->state.state = CS_SPECTATOR;
if(currentmaster>=0) masterupdate = true;
ci->state.lasttimeplayed = lastmillis;
Expand Down Expand Up @@ -2148,6 +2164,7 @@ namespace server
{
sendfile(sender, 2, mapdata, "ri", SV_SENDMAP);
SbPy::triggerEventInt("player_get_map", ci->clientnum);
ci->connectmillis = totalmillis;
}
else sendf(sender, 1, "ris", SV_SERVMSG, "no map to send");
break;
Expand Down Expand Up @@ -2234,13 +2251,46 @@ namespace server
SbPy::triggerEventIntBool("player_pause", ci->clientnum, val != 0);
break;
}
case SV_COPY:
ci->cleanclipboard();
ci->lastclipboard = totalmillis;
goto genericmsg;

case SV_PASTE:
if(ci->state.state!=CS_SPECTATOR) sendclipboard(ci);
goto genericmsg;

case SV_CLIPBOARD:
{
int unpacklen = getint(p), packlen = getint(p);
ci->cleanclipboard(false);
if(ci->state.state==CS_SPECTATOR)
{
if(packlen > 0) p.subbuf(packlen);
break;
}
if(packlen <= 0 || packlen > (1<<16) || unpacklen <= 0)
{
if(packlen > 0) p.subbuf(packlen);
packlen = unpacklen = 0;
}
packetbuf q(32 + packlen, ENET_PACKET_FLAG_RELIABLE);
putint(q, SV_CLIPBOARD);
putint(q, ci->clientnum);
putint(q, unpacklen);
putint(q, packlen);
if(packlen > 0) p.get(q.subbuf(packlen).buf, packlen);
ci->clipboard = q.finalize();
ci->clipboard->referenceCount++;
break;
}

#define PARSEMESSAGES 1
#include "capture.h"
#include "ctf.h"
#undef PARSEMESSAGES

default:
default: genericmsg:
{
int size = server::msgsizelookup(type);
if(size==-1) { disconnect_client(sender, DISC_TAGT); return; }
Expand Down
19 changes: 15 additions & 4 deletions src/fpsgame/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,12 @@ namespace server
string clientmap;
int mapcrc;
bool warned, gameclip, active;

ENetPacket *clipboard;
int lastclipboard;

clientinfo() { reset(); }
~clientinfo() { events.deletecontentsp(); }
clientinfo() : clipboard(NULL) { reset(); }
~clientinfo() { events.deletecontentsp(); cleanclipboard(); }

void addevent(gameevent *e)
{
Expand All @@ -243,15 +246,21 @@ namespace server
warned = false;
gameclip = false;
}

void reassign()
{
state.reassign();
events.deletecontentsp();
timesync = false;
lastevent = 0;
}


void cleanclipboard(bool fullclean = true)
{
if(clipboard) { if(--clipboard->referenceCount <= 0) enet_packet_destroy(clipboard); clipboard = NULL; }
if(fullclean) lastclipboard = 0;
}

void reset()
{
name[0] = team[0] = 0;
Expand All @@ -263,6 +272,7 @@ namespace server
messages.setsizenodelete(0);
ping = 0;
aireinit = 0;
cleanclipboard();
active = false;
mapchange();
}
Expand All @@ -277,6 +287,7 @@ namespace server
}
else return gameoffset + clientmillis;
}

};

struct worldstate
Expand Down
1 change: 1 addition & 0 deletions src/shared/iengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ extern void *getclientinfo(int i);
extern void sendf(int cn, int chan, const char *format, ...);
extern void sendfile(int cn, int chan, stream *file, const char *format = "", ...);
extern void sendpacket(int cn, int chan, ENetPacket *packet, int exclude = -1);
extern void flushserver(bool force);
extern int getnumclients();
extern uint getclientip(int n);
extern void putint(ucharbuf &p, int n);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/igame.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace server
extern void recordpacket(int chan, void *data, int len);
extern void parsepacket(int sender, int chan, packetbuf &p);
extern void sendservmsg(const char *s);
extern bool sendpackets();
extern bool sendpackets(bool force=false);
extern void serverinforeply(ucharbuf &req, ucharbuf &p);
extern void serverupdate();
extern bool servercompatible(char *name, char *sdec, char *map, int ping, const vector<int> &attr, int np);
Expand Down

0 comments on commit 64b1f5c

Please sign in to comment.