Code: Select all
string isGame = (bool)roomObj["isGame"] ? "1" : "0";
string exitCurrentRoom = "1";
string maxUsers = roomObj.ContainsKey("maxUsers") ? Convert.ToString(roomObj["maxUsers"]) : "0";
string maxSpectators = roomObj.ContainsKey("maxSpectators") ? Convert.ToString(roomObj["maxSpectators"]) : "0";
if ((bool)roomObj["isGame"] && roomObj["exitCurrent"] != null)
exitCurrentRoom = (bool)roomObj["exitCurrent"] ? "1" : "0";
string xmlMsg = "<room tmp='1' gam='" + isGame + "' spec='" + maxSpectators + "' exit='" + exitCurrentRoom + "'>";
xmlMsg += "<name><![CDATA[" + (roomObj["name"] == null ? "" : roomObj["name"]) + "]]></name>";
xmlMsg += "<pwd><![CDATA[" + (roomObj["password"] == null ? "" : roomObj["password"]) + "]]></pwd>";
xmlMsg += "<max>" + maxUsers + "</max>";
if (roomObj["uCount"] != null)
xmlMsg += "<uCnt>" + ((bool)roomObj["uCount"] ? "1" : "0") + "</uCnt>";
// Set extension for room
if (roomObj["extension"] != null)
{
xmlMsg += "<xt n='" + ((Hashtable)roomObj["extension"])["name"];
xmlMsg += "' s='" + ((Hashtable)roomObj["extension"])["script"] + "' />";
}
// Set Room Variables on creation
if (roomObj["vars"] == null)
xmlMsg += "<vars></vars>";
The central issue is that this code expects various keys to be present in the incoming HashTable. The absence of certain fields causes an exception: Here is and example:
Code: Select all
string isGame = (bool)roomObj["isGame"] ? "1" : "0";
Other parts of this code perform better by checking for the existance of the key prior to accessing it:
Code: Select all
roomObj.ContainsKey("maxUsers")
Seems like this should be done consistantly throughout this section.
The only other issue I found is that there is an inconsistancy between the documentation in the .NET API and the code for the "exitCurrentRoom". The docs list it as "exitCurrentRoom" whereas the code is looking for "exitCurrent".
You can successfully create a room despite these issues by specifying most, if not all the fields in the HashTable, similar to this:
Code: Select all
Hashtable roomObj = new Hashtable();
roomObj.Add("name", "myRoomName");
roomObj.Add("password", "myPassword);
roomObj.Add("exitCurrentRoom", false);
roomObj.Add("exitCurrent", false);
roomObj.Add("maxUsers", 20);
roomObj.Add("uCount", true);
roomObj.Add("maxSpectators", 0);
roomObj.Add("isGame", false);
roomObj.Add("extension", null);
roomObj.Add("vars", null);
Hope this helps!
Craig