Create room server side

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Create room server side

Postby Skills07 » 21 Feb 2017, 12:38

Hello

I need an help to create a room server side.
I want to create a room only when i have insert a clan on a database.

so i do this on server side

Code: Select all

 obj = dbmanager.executeInsert(sql,
                        new Object[] {clan_name, user_founder, stemma, descrizione, min_trophy, position, type, maxUsers, minUsers});
            
           ISFSObject success = new SFSObject();
            success.putUtfString("success" ,"Clan successfully registrated");
            send("clan", success, user);
            
       createRoom(user,params);


and then my method create room

Code: Select all

private void createRoom(User sender, ISFSObject params){
        
      RoomExtensionSettings res = new RoomExtensionSettings("Login","ClanExtension");
            CreateRoomSettings crs = new CreateRoomSettings();
            String clan_name = params.getUtfString("clan_name");
            crs.setAutoRemoveMode(SFSRoomRemoveMode.NEVER_REMOVE);
            crs.setName(clan_name);
            crs.setGroupId("clan_name " + clan_name);
            crs.setMaxVariablesAllowed(20);
            crs.setMaxUsers(20);
            crs.setDynamic(true);
            crs.setExtension(res);
           
            ISFSObject reback = SFSObject.newInstance();
            try {
               getApi().createRoom(sender.getZone(),crs,sender);
               reback.putBool("success", true);
            } catch (SFSCreateRoomException e) {
               e.printStackTrace();
               reback.putBool("success", false);
            }finally{
               send("createRoom", reback, sender);
            }
         }



but on smartfox i have this error:

Code: Select all

21 feb 2017 | 13:37:27,181 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | STATE: WAIT_NEW_PACKET
21 feb 2017 | 13:37:27,181 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | NORMAL SIZED PACKET: 201
21 feb 2017 | 13:37:27,181 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | <<< PACKET COMPLETE >>>
21 feb 2017 | 13:37:27,182 | DEBUG | SFSWorker:Sys:4 | v2.protocol.SFSProtocolCodec |     |
   (sfs_object) p:
      (sfs_object) p:
         (int) symbol: 0
         (utf_string) descr: superpippoclan
         (int) minUsers: 1
         (int) maxUsers: 20
         (int) founder: 3
         (utf_string) name: superpippoclan
         (utf_string) location: Internazionale
         (int) type: 0
         (int) trophies: 400
         
      
      (int) r: 2
      (utf_string) c: clan
      
   
   (short) a: 13
   (byte) c: 1
   

21 feb 2017 | 13:37:27,182 | DEBUG | SFSWorker:Ext:1 | controllers.v290.ExtensionReqController |     | [Req Type: (Tcp), Sender: { Id: 3, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:55806 }]
21 feb 2017 | 13:37:27,183 | DEBUG | SFSWorker:Ext:1 | controllers.v290.ExtensionReqController |     |
   (sfs_object) p:
      (int) symbol: 0
      (utf_string) descr: superpippoclan
      (int) minUsers: 1
      (int) maxUsers: 20
      (int) founder: 3
      (utf_string) name: superpippoclan
      (utf_string) location: Internazionale
      (int) type: 0
      (int) trophies: 400
      
   
   (int) r: 2
   (utf_string) c: clan
   

21 feb 2017 | 13:37:27,184 | INFO  | SFSWorker:Ext:1 | Extensions |     | {Server}: Sto chiedendo di registrare un clan al server
21 feb 2017 | 13:37:27,185 | INFO  | SFSWorker:Ext:1 | Extensions |     | {Server}: sono entrato nel primo try
21 feb 2017 | 13:37:27,188 | DEBUG | SFSWorker:Ext:1 | v2.db.SFSDBManager |     | Execute Query SQL: com.mysql.jdbc.JDBC42PreparedStatement@57571e0: SELECT * FROM Clan WHERE  clan_name='superpippoclan'
21 feb 2017 | 13:37:27,191 | INFO  | SFSWorker:Ext:1 | Extensions |     | {Server}: [SFSArray, size: 0]
21 feb 2017 | 13:37:27,191 | INFO  | SFSWorker:Ext:1 | Extensions |     | {Server}: registriamo il clan nel nostro database
21 feb 2017 | 13:37:27,194 | DEBUG | SFSWorker:Ext:1 | v2.db.SFSDBManager |     | Execute Insert SQL: com.mysql.jdbc.JDBC42PreparedStatement@60dc7144: INSERT into Clan(clan_name, utente_fondatore, stemma, descrizione, min_trofei, position, tipo, maxUsers, minUsers) values ('superpippoclan', 3, 0, 'superpippoclan', 400, 'Internazionale', 0, 20, 1)
21 feb 2017 | 13:37:27,201 | DEBUG | SFSWorker:Ext:1 | v2.protocol.SFSProtocolCodec |     | {OUT}: CallExtension
21 feb 2017 | 13:37:27,202 | DEBUG | SFSWorker:Ext:1 | protocol.binary.BinaryIoHandler |     | Binary size: 85
12 00 03 00 01 70 12 00 03 00 01 70 12 00 01 00    .....p.....p....
07 73 75 63 63 65 73 73 08 00 1D 43 6C 61 6E 20    .success...Clan.
73 75 63 63 65 73 73 66 75 6C 6C 79 20 72 65 67    successfully.reg
69 73 74 72 61 74 65 64 00 01 72 04 00 00 00 02    istrated..r.....
00 01 63 08 00 04 63 6C 61 6E 00 01 61 03 00 0D    ..c...clan..a...
00 01 63 02 01                                     ..c..           

21 feb 2017 | 13:37:27,203 | DEBUG | SFSWorker:Ext:1 | v2.protocol.SFSProtocolCodec |     | {OUT}: CallExtension
21 feb 2017 | 13:37:27,203 | DEBUG | SFSWorker:Ext:1 | protocol.binary.BinaryIoHandler |     | Binary size: 50
12 00 03 00 01 70 12 00 03 00 01 70 12 00 00 00    .....p.....p....
01 72 04 00 00 00 02 00 01 63 08 00 0A 63 72 65    .r.......c...cre
61 74 65 52 6F 6F 6D 00 01 61 03 00 0D 00 01 63    ateRoom..a.....c
02 01                                              ..             

21 feb 2017 | 13:37:27,204 | ERROR | SFSWorker:Ext:1 | controllers.v290.ExtensionReqController |     | java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Error while handling client request in extension: { Ext: Server, Type: JAVA, Lev: ROOM, { Zone: Login }, [ Room: The Lobby, Id: 2, Group: default, isGame: false ] }
Extension Cmd: clan
+--- --- ---+
Stack Trace:
+--- --- ---+
java.util.concurrent.ConcurrentHashMap.get(Unknown Source)
java.util.concurrent.ConcurrentHashMap.containsKey(Unknown Source)
com.smartfoxserver.v2.entities.managers.SFSRoomManager.containsRoom(SFSRoomManager.java:465)
com.smartfoxserver.v2.entities.managers.SFSRoomManager.validateRoomName(SFSRoomManager.java:696)
com.smartfoxserver.v2.entities.managers.SFSRoomManager.createRoom(SFSRoomManager.java:92)
com.smartfoxserver.v2.entities.SFSZone.createRoom(SFSZone.java:279)
com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:731)
com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:701)
clanserver.ClanRegistrationHandler.createRoom(ClanRegistrationHandler.java:108)
clanserver.ClanRegistrationHandler.handleClientRequest(ClanRegistrationHandler.java:76)
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:208)
com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:174)
com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

21 feb 2017 | 13:37:27,205 | DEBUG | SFSWorker:Ext:1 | controllers.v290.ExtensionReqController |     | Extension call executed in: 21.78005
21 feb 2017 | 13:38:03,999 | INFO  | SocketReader | bitswarm.sessions.DefaultSessionManager |     | Session removed: { Id: 3, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:55806 }
21 feb 2017 | 13:38:04,003 | DEBUG | SFSWorker:Sys:4 | entities.managers.SFSRoomManager |     | User: christianthebest removed from Room: The Lobby
21 feb 2017 | 13:38:04,004 | DEBUG | SFSWorker:Ext:2 | v2.buddylist.SFSBuddyListManager |     | Skipping BuddyList save request. No BuddyList available for: christianthebest
21 feb 2017 | 13:38:04,005 | INFO  | SFSWorker:Sys:4 | v2.api.SFSApi |     | User disconnected: { Zone: Login }, ( User Name: christianthebest, Id: 1, Priv: 0, Sess: 127.0.0.1:55806 ) , SessionLen: 51260, Type: Unity
21 feb 2017 | 13:39:03,987 | DEBUG | pool-1-thread-1 | entities.managers.SFSZoneManager$TrafficMeterExecutor |     | Traffic Monitor update: 0.063813ms.



how can i solve this problem???
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Create room server side

Postby Lapo » 21 Feb 2017, 14:21

I am not sure about what you're asking. It seems you already have the written the code.

What is your question?
Lapo
--
gotoAndPlay()
...addicted to flash games
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Create room server side

Postby Skills07 » 22 Feb 2017, 07:59

But i need to say, if i launch an extension in a room, this extension cannot create other room? is it correct?

Sure it can.
As usual ---> getApi().createRoom(...)


i think i need a zone with my ext and this ext can create the rooms dinamically... is it correct??

No, any extension can do it.

cheers
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Create room server side

Postby Skills07 » 22 Feb 2017, 14:55

Sorry but i have modify my message,

I didn't find the respond of the question.

I try what you suggest
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Create room server side

Postby Skills07 » 23 Feb 2017, 11:33

Sorry Lapo
but i don't understand how can i create a room dinamically.

I have used the code posted at the first topic but it doesn't work.

I explain my situation

I have a zone called Lobby, here i have 3 rooms, in lobby room i have clan extension that doing something.
My action is createclanhandler(a method of clan ext)

Here when i insert in database i need to create a room with the name of the clan because i need to do a chat group only for the clan.

How can i do this??
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Create room server side

Postby Lapo » 23 Feb 2017, 16:23

Skills07 wrote:Sorry Lapo
but i don't understand how can i create a room dinamically.

I have used the code posted at the first topic but it doesn't work.

What does it mean "it doesn't work"?
What error are you seeing exactly?


I have a zone called Lobby, here i have 3 rooms, in lobby room i have clan extension that doing something.

This is confusing. Is the Zone called "Lobby" or the Room called "Lobby" or both??

Here when i insert in database i need to create a room with the name of the clan because i need to do a chat group only for the clan.
How can i do this??

You should do as I said, and if you have issues explain exactly what error you get.
Lapo

--

gotoAndPlay()

...addicted to flash games
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Create room server side

Postby Skills07 » 24 Feb 2017, 08:12

Sorry Lapo i can explain you as well

I have a zone called LOBBY and in this zone I have a room called THE LOBBY.

yesterday on myext handler i got an error on the creation of the room dinamically by server side.

The problem was a declaration of this

Code: Select all

RoomExtensionSettings res = new RoomExtensionSettings("Server","clanserver.ClanExtension");


because this istruction need the name of the package of the extension.

Now on consolle i have this message

Code: Select all

23 feb 2017 | 15:36:32,282 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | STATE: WAIT_NEW_PACKET
23 feb 2017 | 15:36:32,282 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | NORMAL SIZED PACKET: 184
23 feb 2017 | 15:36:32,282 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | <<< PACKET COMPLETE >>>
23 feb 2017 | 15:36:32,283 | DEBUG | SFSWorker:Sys:4 | v2.protocol.SFSProtocolCodec |     |
   (sfs_object) p:
      (sfs_object) p:
         (int) symbol: 0
         (utf_string) descr: dddddd
         (int) minUsers: 1
         (int) maxUsers: 20
         (int) founder: 3
         (utf_string) name: ddddd
         (utf_string) location: Internazionale
         (int) type: 0
         (int) trophies: 0
         
      
      (int) r: 2
      (utf_string) c: clan
      
   
   (short) a: 13
   (byte) c: 1
   

23 feb 2017 | 15:36:32,285 | DEBUG | SFSWorker:Ext:4 | controllers.v290.ExtensionReqController |     | [Req Type: (Tcp), Sender: { Id: 1, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:52615 }]
23 feb 2017 | 15:36:32,285 | DEBUG | SFSWorker:Ext:4 | controllers.v290.ExtensionReqController |     |
   (sfs_object) p:
      (int) symbol: 0
      (utf_string) descr: dddddd
      (int) minUsers: 1
      (int) maxUsers: 20
      (int) founder: 3
      (utf_string) name: ddddd
      (utf_string) location: Internazionale
      (int) type: 0
      (int) trophies: 0
      
   
   (int) r: 2
   (utf_string) c: clan
   

23 feb 2017 | 15:36:32,286 | INFO  | SFSWorker:Ext:4 | Extensions |     | {Server}: Sto chiedendo di registrare un clan al server
23 feb 2017 | 15:36:32,286 | INFO  | SFSWorker:Ext:4 | Extensions |     | {Server}: sono entrato nel primo try
23 feb 2017 | 15:36:32,289 | DEBUG | SFSWorker:Ext:4 | v2.db.SFSDBManager |     | Execute Query SQL: com.mysql.jdbc.JDBC42PreparedStatement@6acd76bc: SELECT * FROM Clan WHERE  clan_name='ddddd'
23 feb 2017 | 15:36:32,290 | INFO  | SFSWorker:Ext:4 | Extensions |     | {Server}: [SFSArray, size: 0]
23 feb 2017 | 15:36:32,291 | INFO  | SFSWorker:Ext:4 | Extensions |     | {Server}: registriamo il clan nel nostro database
23 feb 2017 | 15:36:32,292 | DEBUG | SFSWorker:Ext:4 | v2.db.SFSDBManager |     | Execute Insert SQL: com.mysql.jdbc.JDBC42PreparedStatement@1a3f24d1: INSERT into Clan(clan_name, utente_fondatore, stemma, descrizione, min_trofei, position, tipo, maxUsers, minUsers) values ('ddddd', 3, 0, 'dddddd', 0, 'Internazionale', 0, 20, 1)
23 feb 2017 | 15:36:32,316 | DEBUG | SFSWorker:Ext:4 | v2.protocol.SFSProtocolCodec |     | {OUT}: CallExtension
23 feb 2017 | 15:36:32,317 | DEBUG | SFSWorker:Ext:4 | protocol.binary.BinaryIoHandler |     | Binary size: 85
12 00 03 00 01 70 12 00 03 00 01 70 12 00 01 00    .....p.....p....
07 73 75 63 63 65 73 73 08 00 1D 43 6C 61 6E 20    .success...Clan.
73 75 63 63 65 73 73 66 75 6C 6C 79 20 72 65 67    successfully.reg
69 73 74 72 61 74 65 64 00 01 72 04 00 00 00 02    istrated..r.....
00 01 63 08 00 04 63 6C 61 6E 00 01 61 03 00 0D    ..c...clan..a...
00 01 63 02 01                                     ..c..           

23 feb 2017 | 15:36:32,328 | INFO  | SFSWorker:Ext:4 | entities.managers.SFSRoomManager |     | Room created: { Zone: Login }, [ Room: ddddd, Id: 5, Group: clan_name ddddd, isGame: false ], type = SFSRoom
23 feb 2017 | 15:36:32,329 | DEBUG | SFSWorker:Ext:4 | v2.protocol.SFSProtocolCodec |     | {OUT}: CallExtension
23 feb 2017 | 15:36:32,330 | DEBUG | SFSWorker:Ext:4 | protocol.binary.BinaryIoHandler |     | Binary size: 61
12 00 03 00 01 70 12 00 03 00 01 70 12 00 01 00    .....p.....p....
07 73 75 63 63 65 73 73 01 01 00 01 72 04 00 00    .success....r...
00 02 00 01 63 08 00 0A 63 72 65 61 74 65 52 6F    ....c...createRo
6F 6D 00 01 61 03 00 0D 00 01 63 02 01             om..a.....c..   


it seems it create the room but on smartfox panel i can't see this room.

My question is i need to create fixed room in the game because i need to create chat group of the clan.
When a clan is deleted i delete the room of the clan.

So i can tell you

i have a user PIPPO that create a clan named PIPPOCLAN, on this create in database i want smartfox create a room called PIPPOCLAN.

Then i have user TOPOLINO, PAPERINO and PLUTO that join in PIPPOCLAN and the they can chat in PIPPOCLAN ROOM.

When PIPPO is bored he can destroy the clan, then smartfox have to destroy the room PIPPOCLAN ROOM.

How can i do this??

Thanks for your help
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Create room server side

Postby Lapo » 24 Feb 2017, 09:13

If you are creating a Room from the server side (Extension) all you have to do is calling getApi().createRoom(...) with the parameter you can see in the docs.

This will create a Room or throw an Exception, so it's pretty easy to see if the Room was created.

but on smartfox panel i can't see this room.

You must use the AdminTool > Zone Monitor module, select the correct Zone and also make sure you change the "Group" drop down to "[Any]" so that it will show all Rooms in any Group.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Create room server side

Postby Skills07 » 24 Feb 2017, 09:27

Lapo wrote:If you are creating a Room from the server side (Extension) all you have to do is calling getApi().createRoom(...) with the parameter you can see in the docs.

This will create a Room or throw an Exception, so it's pretty easy to see if the Room was created.

but on smartfox panel i can't see this room.

You must use the AdminTool > Zone Monitor module, select the correct Zone and also make sure you change the "Group" drop down to "[Any]" so that it will show all Rooms in any Group.

Cheers



Sorry Lapo but this code is correct because i have the message that create the room

Code: Select all

private void createRoom(User sender, ISFSObject params){
       
      RoomExtensionSettings res = new RoomExtensionSettings("Login","clanserver.ClanExtension");
            CreateRoomSettings crs = new CreateRoomSettings();
            String clan_name = params.getUtfString("clan_name");
            crs.setAutoRemoveMode(SFSRoomRemoveMode.NEVER_REMOVE);
            crs.setName(clan_name);
            crs.setGroupId("clan_name " + clan_name);
            crs.setMaxVariablesAllowed(20);
            crs.setMaxUsers(20);
            crs.setDynamic(true);
            crs.setExtension(res);
           
            ISFSObject reback = SFSObject.newInstance();
            try {
               getApi().createRoom(sender.getZone(),crs,sender);
               reback.putBool("success", true);
            } catch (SFSCreateRoomException e) {
               e.printStackTrace();
               reback.putBool("success", false);
            }finally{
               send("createRoom", reback, sender);
            }
         }



sorry but in panel zone i can't see anything

Image
Last edited by Skills07 on 24 Feb 2017, 09:33, edited 1 time in total.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Create room server side

Postby Lapo » 24 Feb 2017, 09:28

Does the client receive the Room update?
Lapo

--

gotoAndPlay()

...addicted to flash games
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Create room server side

Postby Skills07 » 24 Feb 2017, 09:34

Lapo wrote:Does the client receive the Room update?


i think no, i have to tell this to my collaborator that does the client side of the coding.

can you send me a portion of code that does the update?? like a syntax example
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Create room server side

Postby Lapo » 24 Feb 2017, 10:24

When a Room is created the client receives a SFSEvent.ROOM_ADD event.
Of course, if the client is already logged in when the Room is created.
Lapo

--

gotoAndPlay()

...addicted to flash games
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Create room server side

Postby Skills07 » 24 Feb 2017, 13:38

Ok i did it!

but if i shut down smartfox server my rooms disappheard(like an elimination)

I want the rooms are persistent

and on server side i have setted

setautoRemoveMode(Never_Remove)

is it ok???
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Create room server side

Postby Lapo » 24 Feb 2017, 16:08

Persistent Rooms must be created in the Configuration of the server.
See --> AdminTool > Zone Configurator

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Create room server side

Postby Skills07 » 27 Feb 2017, 08:38

ah ok,

so we cannot create dinamically persistent room on server side but only a temporary creation.

i want to say how can i create a chat group of a clan, because i cannot say how many clans i have in my game.

My idea was if i have a creation i can create a room for a chat of that clan.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 107 guests