package Sync import Thread import HashList public function boolean.sync(player source) returns boolean var i = 0 if GetLocalPlayer() == source if this i = 1 var i2 = i.sync(source) if i2 == 0 return false else return true /** syncs the given int from the source player and returns the synced message */ public function int.sync(player source) returns int Thread t = new Thread() let localKey = "message" + GetLocalPlayer().getId().toString() let sourceKey = "message" + source.getId().toString() let missionKey = messageCount.toString() messageCount++ StoreInteger(gc, missionKey, localKey, this) SyncStoredInteger(gc, missionKey, localKey) var localSynced = false // wait until message is there for source while true if HaveStoredInteger(gc, missionKey, sourceKey) if not localSynced t.sync() localSynced = true if t.isSynced() // end loop when all other threads are finished break TriggerSyncStart() TriggerSyncReady() var result = GetStoredInteger(gc, missionKey, sourceKey) FlushStoredMission(gc, missionKey) destroy t return result /** syncs the given message from the source player and returns the synced message */ public function string.sync(player source) returns string HashList ints = new HashList() int slen = 0 string result = "" if GetLocalPlayer() == source slen = this.length() slen = slen.sync(source) for i = 0 to slen-1 if GetLocalPlayer() == source ints.add( this.substring(i, i+1).toCharsetInt() ) else ints.add(0) ints.sync(source) for sint in ints result += sint.toCharsetString() destroy ints return result gamecache gc var messageCount = 0 /** Used internally for stringsyncing */ function HashList.sync(player source) Thread t = new Thread() let localKey = "message" + GetLocalPlayer().getId().toString() let sourceKey = "message" + source.getId().toString() let missionKey = messageCount.toString() messageCount++ // sync all the messages: for i=0 to this.getSize()-1 let localKey2 = localKey + "_" + i.toString() StoreInteger(gc, missionKey, localKey2, this.get(i)) SyncStoredInteger(gc, missionKey, localKey2) var localSynced = false // wait until all message from source have arrived while true var allMessagesDone = true for i=0 to this.getSize()-1 if not HaveStoredInteger(gc, missionKey, sourceKey + "_" + i.toString()) allMessagesDone = false if allMessagesDone and not localSynced t.sync() localSynced = true if t.isSynced() // end loop when all other threads are finished break TriggerSyncStart() TriggerSyncReady() for i=0 to this.getSize()-1 this.set(i,GetStoredInteger(gc, missionKey, sourceKey + "_" + i.toString())) FlushStoredMission(gc, missionKey) destroy t function initGamecache() gc = InitGameCache("sync") DestroyTimer(GetExpiredTimer()) init CreateTimer().start(.1, function initGamecache)