Follows a (very) rough outline for a server-client architecture in CDO dependent upon keyValues. This is based off of memory, from that one project I was making before account ban 1. It has the potential to do truly wonderful things, if used correctly.
Prerequisites:
First off, you would need to establish the server. This would be one of the people currently using the project.
var serverIdConnection = new Connection("serverId",function(e){
if(getTime()-e[1]>SERVERTIMEOUT){ //server timeout is a predefined constant
window.serverIdConnection.Post(new Request(uid), function(){
setTimeout(function(){if(window.serverIdConnection.lastValue==uid){meIsServer=true}})
}) //preferably the uid value given from Vault (has md5)
}else{serverId=e[0]}
});
Along with that, in the draw function would go:
if(meIsServer)serverIdConnection.Post(new Request(uid))
We now have something which will allow every player to know who the big daddy server is. The next part details a structure that could be used to create your custom server functions, that can sync across every player's device.
var serverBin = new Connection("bin"+serverId, function(e){
e.forEach(function(a){
if(pastReqs.indexOf(JSON.stringify(a))==-1){
SERVERREQUESTS[a[0][0]](a[0][1]) //serverrequests is a constant list of functions that take 1 parameter (can be list) and do stuff with it, whatever you want
pastReqs.push(JSON.stringify(a))
}
})
})
There you have it! To my knowledge, the first ever CDO native Server-Client architecture! Credit me if using please!
EDIT: Adam was kind enough to give me the Fibre library:
/*
/===========================\
| Fibre v1.1.4 |
| Made by Ravage |
| Basic connections library |
\===========================/
For those who don't know, use the "new" keyword to create an object instance:
new objectName(parameters)
*/
//Basic connection object
//<name> - keyValue name where data is fetched. Can be changed anytime.
//<callback> - function that activates with the online data as its parameter
//<condition> - optional - condition to check if requests can be run
// Note that if it turns to false, you have to call
// <connectionName>.Action() to turn it on again
//Class methods:
// Connection.Action, starts up the connection
// - Note that you must call it, it isn't automatic, for obvious reasons
// Connection.Post, setting the keyValue being fetched
// - NEVER use setKeyValue to set it, it freezes up everything
// - Takes one parameter, the value that you are setting
function Connection(name, callback, condition){
this.name = name;
this.callback = callback;
this.condition = condition || function(){return true};
this.data = undefined;
this.paused = false; //Can be changed at free will
this.activePost = false; //DO NOT TOUCH
this.running = true;
this.Action = function(){
this.running = true;
getKeyValue(this.name, function(a){
this.data = a;
this.callback(a);
if(this.condition(a)&&!this.paused&&!this.activePost){
this.Action();
}
this.running = false;
}.bind(this));
}.bind(this);
this.Post = function(toPost, callback){
if(!this.activePost){
callback = callback || function(){};
//Whatever you do, DO NOT use setKeyValue on the name of an active connection.
//Due to a strange behaviour, that will freeze up the whole thing.
this.activePost = true;
setKeyValue(this.name, toPost, function(){
this.activePost = false;
if(!this.running){
this.Action(); //Revive the connection
}
callback();
}.bind(this));
}
}.bind(this);
}