Put Created Rooms into Database

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

x.Mara.x
Posts: 23
Joined: 18 Dec 2008, 20:03

Put Created Rooms into Database

Postby x.Mara.x » 05 Jan 2009, 19:48

Well.. i started making my own.. using your technique.. this time though.. with this code:

(in the mia.as)

Code: Select all

function init()
{
        function crearcasa () {
         var roomObj:Object      = new Object()
         roomObj.name = cNombre
         insca = new LoadVars();
         insca.cNombre = cNombre
         insca.sendAndLoad("insertarcasa.php", form_lv,"POST");
insca.onLoad = function() {
   if(this.statuss == "ok") {
      trace("Insertada");
   } else {
      if(this.statusss == "ko") {
         trace("Error");
      }
   }
         _server.createRoom(roomObj);
      }
      }

}

function destroy()
{
        trace("Bye bye!")
}

function handleRequest(cmd, params, user, fromRoom)
{
       
        if (cmd == "double")
        {
                var response = {}
               
                response._cmd = "double"
                response.values = []
               
                for (var i = 0; i < params.values.length; i++)
                {
                        var n = params.values[i]
                        response.values[i] = n * 2
                }
               
                _server.sendResponse(response, -1, null, [user])
        }
}

function handleInternalEvent(evt)
{
        // Simply print the name of the event that was received
        trace("Event received: " + evt.name)
}


And in the .fla, when they push a button..

Code: Select all

on(release) {
   var cObj = new Object()
   cObj.cNombre = "hola";
   xt = {}
   xt.name = "mia"
   xt.script = "mia.as"
   cObj.extension      = xt
   

  crearcasa(cObj);
}

But again.. its like the objects are never sent to the extension.. it gives me no answer what so ever and the information is not added to the mysql table.
Last edited by x.Mara.x on 06 Jan 2009, 19:39, edited 1 time in total.
User avatar
Lapo
Site Admin
Posts: 21723
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 06 Jan 2009, 07:07

sorry what is this posted related to?
The "mmm" title doesn't sound like a request for help, the topic doesn't start with request that is understandable, and it was posted in the "features whishlist" section... :roll:

Could you please let us know what is your question? And use a more appropriate title?

I am moving the post to the "Generic Help" section
Please read this for future requests -> viewtopic.php?t=3307
Lapo
--
gotoAndPlay()
...addicted to flash games
x.Mara.x
Posts: 23
Joined: 18 Dec 2008, 20:03

SORRY!

Postby x.Mara.x » 06 Jan 2009, 19:39

I am REALLY sorry for the title.. I thought i was answering to a post or something sorry sorry.. may I continue my post though?
User avatar
Lapo
Site Admin
Posts: 21723
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 06 Jan 2009, 20:08

Yes, please let me know if you want to continue here and which other post are you referring to.

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
x.Mara.x
Posts: 23
Joined: 18 Dec 2008, 20:03

this

Postby x.Mara.x » 06 Jan 2009, 21:59

I mean this topic sorry.. So i will follow to not fill up this topic with a lot of unuseful messages.. if you dont think it belongs here feel free to move it :D
i have an extension that they passed me, and i would like in that extension.. after a room is created to put that room into the database.. this is what i have:

Code: Select all

 /*
* SmartFoxServer PRO
* Simple Extension Example
* v 1.0.0
*
* (c) 2005 gotoAndPlay()
*
*
* Extensions Overview:
* -----------------------------------------------------------------
* Every extension must implement four basic methods:
*
* init(), destroy(), handleRequest(), handleInternalEvent()
*
* init()         It's the initialization point of the extension
*             This method is invoked by the server on the extension as soon as it is loaded
*             You can put here all your initialization code.
*
* destroy()         This method is called by the server when the extension is going to be destroyed
*             You should always put in this method the necessary code to release the resources
*             you were using like setInterval(s), database connections etc...
*
* handleRequest()      This method receives the client requests
*
* handleInternalEvent()      Handles internal server events. Events are:
*
*             userJoin   when a user joins the room / zone
*             userExit   when a user exits a room
*             userLost   when a user disconnects
*             newRoom      a new room was created in the zone
*             roomLost   a room was destroyed in the zone
*             loginRequest   a custom login request arrived   

*/
/*
* Initializion point:
*
* this function is called as soon as the extension
* is loaded in the server.
*
* You can add here all the initialization code
*
*/
function init() {

   trace("Hello from the Simple Extension Example!");
}
/*
* This method is called by the server when an extension
* is being removed / destroyed.
*
* Always make sure to release resources like setInterval(s)
* open files etc in this method.
*
* In this case we delete the reference to the databaseManager
*/

function destroy() {
   trace("Bye bye!");
}
/*
*
* Handle Client Requests
*
* cmd       = a string with the client command to execute
* params    = list of parameters expected from the client
* user       = the User object representing the sender
* fromRoom    = the id of the room where the request was generated
*
*/
function handleRequest(cmd, params, user, fromRoom, roomObj) {
   if (cmd == "double") {
      var response = {};
      response.nombre = [];
      for (var i = 0; i<params.nombre.length; i++) {
         var n = params.nombre[i];
         response.nombre[i] = n;
      }
      function salvar() {
   insca = new LoadVars();
         insca.cNombre = n
         insca.sendAndLoad("insertarcasa.php", insca,"POST");
insca.onLoad = function() {
   if(this.statuss == "ok") {
      trace("Insertada");
   } else if(this.statuss == "ko") {
         trace("Error");
      }
   }
}
response.creo = [];
response.iderom = [];
      var k = params.dueno[0];
      var describeRoom = params.desc[0];
      var cantu = params.cantu[0];
      response.pwd = [];
      for (var w = 0; w<params.pwd.length; w++) {
         var t = params.pwd[w];
         response.pwd[w] = t;
         var rObj = {};
         rObj.name = n;
         rObj.pwd = t;
         rObj.maxU = cantu;
         rObj.maxS = 0;
         rObj.isGame = false;
         var newRoom = _server.createRoom(rObj, null);
         if (newRoom != null) {
            trace("Great the room was created -> add your vars here");
            vars = new Array();
            vars.push({name:"duenoactu", val:k, setOwnership:false});
            _server.setRoomVariables(newRoom, null, vars, false, true);
            response.iderom[0] = newRoom.getId();
            salvar();
hd = n.split(" ");
   hz = hd.join("%20");
      response.creo[0] = "si";
      newRoom.properties.put("descripcion", describeRoom)
newRoom.properties.put("voto", "0_0")


} else {
   response.creo[0] = "no";         
   trace("A problem occurred, better check the server logs");
         }
      }
      /*
                  *
                  * Send response back to client
                  *
                  * sendResponse(response, fromRoom, sender, recipients, type)
                  *
                  * response = an object with the _cmd property specifying the name of the response command
                  * fromRoom = the id of the room where the response comes from (-1 if not needed)
                  * sender   = the user sending the response (null if not needed)
                  * recipients = a list of user that should receive the reponse
                  * type = can be "xml" or "str". It represent the message format
                  *
                  */
      _server.sendResponse(response, -1, null, [user]);
   }
}
/*
* This method handles internal events

* Internal events are dispactched by the Zone or Room where the extension is attached to
*
* the (evt) object
*/
function handleInternalEvent(evt) {
   // Simply print the name of the event that was received
   trace("Event received: "+evt.name);
}

In the

salvar() function, I try to send some objects to a insertarcasa.php file.. and from there it inserts the value into the database.. but the first time i tried this it inserted only in the "owner" column the value "hola" and nothing in the value for the room name which would be the "nombre" column.. then i tried it again and again.. and nothing would be inserted in the db.. here is the insertarcasa.php:

Code: Select all

<?php
include('conectar.php');
mysql_query("INSERT into salas(id,owner,nombre) VALUES ('NULL','hola','".$_POST['cNombre']."')") or die(mysql_error());

echo"&statuss=ok";

?>

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 19 guests