Brought up to date with the private repository (feea4c7)

This commit is contained in:
S committed 2026-10-14 20:57:33 +03:00
1 parent 1aa738d692
commit 1b1df1ae48
7925 files changed
+2617237 -20

No files matched your search

@@ -0,0 +1,127 @@
package it.gotoandplay.smartfoxserver.util
{
public class Entities
{
private static var ascTab:Array = [];
ascTab[">"] = ">";
ascTab["<"] = "&lt;";
ascTab["&"] = "&amp;";
ascTab["\'"] = "&apos;";
ascTab["\""] = "&quot;";
private static var ascTabRev:Array = [];
ascTabRev["&gt;"] = ">";
ascTabRev["&lt;"] = "<";
ascTabRev["&amp;"] = "&";
ascTabRev["&apos;"] = "\'";
ascTabRev["&quot;"] = "\"";
private static var hexTable:Array = new Array();
hexTable["0"] = 0;
hexTable["1"] = 1;
hexTable["2"] = 2;
hexTable["3"] = 3;
hexTable["4"] = 4;
hexTable["5"] = 5;
hexTable["6"] = 6;
hexTable["7"] = 7;
hexTable["8"] = 8;
hexTable["9"] = 9;
hexTable["A"] = 10;
hexTable["B"] = 11;
hexTable["C"] = 12;
hexTable["D"] = 13;
hexTable["E"] = 14;
hexTable["F"] = 15;
public function Entities()
{
super();
}
public static function encodeEntities(st:String) : String
{
var ch:String = null;
var cod:int = 0;
var strbuff:String = "";
for(var i:int = 0; i < st.length; i++)
{
ch = st.charAt(i);
cod = st.charCodeAt(i);
if(cod == 9 || cod == 10 || cod == 13)
{
strbuff += ch;
}
else if(cod >= 32 && cod <= 126)
{
if(ascTab[ch] != null)
{
strbuff += ascTab[ch];
}
else
{
strbuff += ch;
}
}
else
{
strbuff += ch;
}
}
return strbuff;
}
public static function decodeEntities(st:String) : String
{
var strbuff:String = null;
var ch:String = null;
var ent:String = null;
var chi:String = null;
var item:String = null;
var i:int = 0;
strbuff = "";
while(i < st.length)
{
ch = st.charAt(i);
if(ch == "&")
{
ent = ch;
do
{
i++;
chi = st.charAt(i);
ent += chi;
}
while(chi != ";" && i < st.length);
item = ascTabRev[ent];
if(item != null)
{
strbuff += item;
}
else
{
strbuff += String.fromCharCode(getCharCode(ent));
}
}
else
{
strbuff += ch;
}
i++;
}
return strbuff;
}
public static function getCharCode(ent:String) : Number
{
var hex:String = ent.substr(3,ent.length);
hex = hex.substr(0,hex.length - 1);
return Number("0x" + hex);
}
}
}
@@ -0,0 +1,177 @@
package it.gotoandplay.smartfoxserver.util
{
public class ObjectSerializer
{
private static var instance:ObjectSerializer;
private var debug:Boolean;
private var eof:String;
private var tabs:String;
public function ObjectSerializer(debug:Boolean = false)
{
super();
this.tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t";
this.setDebug(debug);
}
public static function getInstance(debug:Boolean = false) : ObjectSerializer
{
if(instance == null)
{
instance = new ObjectSerializer(debug);
}
return instance;
}
private function setDebug(b:Boolean) : void
{
this.debug = b;
if(this.debug)
{
this.eof = "\n";
}
else
{
this.eof = "";
}
}
public function serialize(o:Object) : String
{
var result:Object = {};
this.obj2xml(o,result);
return result.xmlStr;
}
public function deserialize(xmlString:String) : Object
{
var xmlData:XML = new XML(xmlString);
var resObj:Object = {};
this.xml2obj(xmlData,resObj);
return resObj;
}
private function obj2xml(srcObj:Object, trgObj:Object, depth:int = 0, objName:String = "") : void
{
var i:String = null;
var ot:String = null;
var t:String = null;
var o:* = undefined;
if(depth == 0)
{
trgObj.xmlStr = "<dataObj>" + this.eof;
}
else
{
if(this.debug)
{
trgObj.xmlStr += this.tabs.substr(0,depth);
}
ot = srcObj is Array ? "a" : "o";
trgObj.xmlStr += "<obj t=\'" + ot + "\' o=\'" + objName + "\'>" + this.eof;
}
for(i in srcObj)
{
t = typeof srcObj[i];
o = srcObj[i];
if(t == "boolean" || t == "number" || t == "string" || t == "null")
{
if(t == "boolean")
{
o = Number(o);
}
else if(t == "null")
{
t = "x";
o = "";
}
else if(t == "string")
{
o = Entities.encodeEntities(o);
}
if(this.debug)
{
trgObj.xmlStr += this.tabs.substr(0,depth + 1);
}
trgObj.xmlStr += "<var n=\'" + i + "\' t=\'" + t.substr(0,1) + "\'>" + o + "</var>" + this.eof;
}
else if(t == "object")
{
this.obj2xml(o,trgObj,depth + 1,i);
if(this.debug)
{
trgObj.xmlStr += this.tabs.substr(0,depth + 1);
}
trgObj.xmlStr += "</obj>" + this.eof;
}
}
if(depth == 0)
{
trgObj.xmlStr += "</dataObj>" + this.eof;
}
}
private function xml2obj(x:XML, o:Object) : void
{
var nodeName:String = null;
var node:XML = null;
var objName:String = null;
var objType:String = null;
var varName:String = null;
var varType:String = null;
var varVal:String = null;
var i:int = 0;
var nodes:XMLList = x.children();
for each(node in nodes)
{
nodeName = node.name().toString();
if(nodeName == "obj")
{
objName = node.@o;
objType = node.@t;
if(objType == "a")
{
o[objName] = [];
}
else if(objType == "o")
{
o[objName] = {};
}
this.xml2obj(node,o[objName]);
}
else if(nodeName == "var")
{
varName = node.@n;
varType = node.@t;
varVal = node.toString();
if(varType == "b")
{
o[varName] = varVal == "0" ? false : true;
}
else if(varType == "n")
{
o[varName] = Number(varVal);
}
else if(varType == "s")
{
o[varName] = varVal;
}
else if(varType == "x")
{
o[varName] = null;
}
}
}
}
private function encodeEntities(s:String) : String
{
return s;
}
}
}