Page 1 of 1

Extension Error

Posted: 24 Mar 2011, 01:33
by coolboy714cp
In my extension, I have this coding:

Code: Select all

if (cmd == "fB") {
		//Find buddy
		var zone = _server.getCurrentZone();
		var buddyName = params.buddyName;
		var b = zone.getUserByName(buddyName);
		var bID = b.getUserId();
		trace("Buddy ID: " + bID);
		var res = {};
		res._cmd = "foundBuddy";
		res.buddyID = bID;
		_server.sendResponse(res, -1, null, user);
	}
When I execute it, the server comes up with this error message:
[advancedBuddylistScript.as]: Buddy ID: 1
20:26:48.319 - [ WARNING ] > Error in extension [ advancedBuddylistScript.as ]:
Wrapped java.lang.ClassCastException: it.gotoandplay.smartfoxserver.data.User ca
nnot be cast to java.nio.channels.SocketChannel (advancedBuddylistScript.as#513)
Internal: -1064 -- Line number: (MainLib line: 513)
Does anyone know what I'm doing wrong?[/code]

Posted: 24 Mar 2011, 03:49
by BigFIsh
Try: _server.sendResponse(res, -1, null, [user]);

Posted: 24 Mar 2011, 22:43
by coolboy714cp
Alright that worked, thank you. I just put the extension on the room level by adding this coding to the extension in the <Rooms> tag:

Code: Select all

<Extensions>
					<extension name="aBL" className="advancedBuddylistScript.as" type="script" />
				</Extensions>
And I changed the extension coding to this:

Code: Select all

if (cmd == "fB") {
		//Find buddy
		var zone = _server.getCurrentZone();
		var buddyName = params.buddyName;
		var b = zone.getUserByName(buddyName);
		var bID = b.getUserId();
		var room = _server.getCurrentRoom();
		var roomID = room.getId();
		trace("Buddy ID: " + bID);
		var res = {};
		res._cmd = "foundBuddy";
		res.buddyID = bID;
		_server.sendResponse(res, roomID, null, [user]);
	}
But after doing those two things, I'm getting the following error on the server:
17:35:20.470 - [ WARNING ] > it.gotoandplay.smartfoxserver.exceptions.MissingExt
ensionException: Unrecognized extension name: [ aBL ]! Zone: tv, Room: 43
The extension is placed in the sfsExtensions folder in my SmartFoxServer installation directory.

So, my questions are

1. Is there a way to get the room object without having the extension on the room level?

and

2. How can I fix the error above?

Posted: 24 Mar 2011, 23:07
by BigFIsh
1. Is there a way to get the room object without having the extension on the room level?
I don't follow. Can you please explain more?
2. How can I fix the error above?
- Did you get any errors related to the buddy extension at server launch? If so, this would be the cause.
- Have you restarted the server after making changes to the config.xml?

Posted: 24 Mar 2011, 23:12
by coolboy714cp
- Did you get any errors related to the buddy extension at server launch? If so, this would be the cause.
I don't get any other errors than the one that I posted.
- Have you restarted the server after making changes to the config.xml?
Yes, I restarted it twice in total.
I don't follow. Can you please explain more?
Is there anyway I can put this extension back on the Zone level and call it, rather than putting it on the Room level? I'm unsure about this because in the SmartFoxServer Docs it says "(If the extension is not at Room level you will get a null)."

Posted: 24 Mar 2011, 23:38
by BigFIsh
[url]Is there anyway I can put this extension back on the Zone level and call it, rather than putting it on the Room level? I'm unsure about this because in the SmartFoxServer Docs it says "(If the extension is not at Room level you will get a null)."[/url]

Yes, you can put the extension at zone level. You can get the room instance by calling zone.getRoom(RoomId). _server.getCurrentRoom() is for room level extension, for obvious reasons.

[url]I don't get any other errors than the one that I posted.[/url]

Are you sure about this? Did you get a message saying that the extension have been initialized successfully and there is no error? (this can be found before the "Server started" line).

Posted: 24 Mar 2011, 23:48
by coolboy714cp
Yes, you can put the extension at zone level. You can get the room instance by calling zone.getRoom(RoomId). _server.getCurrentRoom() is for room level extension, for obvious reasons.
Alright, thanks for that. I thought I could do that, I was just double checking. :P
Are you sure about this? Did you get a message saying that the extension have been initialized successfully and there is no error? (this can be found before the "Server started" line).
Yes, the only text that has something to do with that extension before the serverReady event is this:
[advancedBuddylistScript.as]: Advanced buddylist system is activating.
Which is what I put on the init() function of my extension.

Posted: 24 Mar 2011, 23:56
by BigFIsh
Hm, strange.

I can only think of one other reason. Check that your Extenions tag is within the scope of the <Room> or <Zone> tag. i.e.

Code: Select all

<Rooms>
<Room>
<Extension/>
<Room>
<Rooms>
or

Code: Select all

<Zone>
<Extension/>
<Zone>

Posted: 25 Mar 2011, 00:05
by coolboy714cp
I just edited the coding a bit and it is saying the problem is getId() is not a valid function, do you have any idea why that could be?
19:02:22.686 - [ WARNING ] > Error in extension [ advancedBuddylistScript.as ]:
TypeError: Cannot find function getId. (advancedBuddylistScript.as#1628) Interna
l: 51 -- Line number: 50 in file: advancedBuddylistScript.as
This is my new coding:

Code: Select all

function handleRequest(cmd, params, user, fromRoom) {
...
var roomID = fromRoom.getId();
trace("Room Object: " + fromRoom);
trace("Room Object ID: " + fromRoom.getId());
...
}
The extension is now on the Zone level.

Posted: 25 Mar 2011, 00:09
by coolboy714cp
Nevermind, I just rechecked the Docs and found out the fromRoom isn't a room object, but it's a room id instead.