phpFreeChat & Browser MMO Tutorial

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Tim
Posts: 37
Joined: Fri Jun 10, 2011 12:49 am

phpFreeChat & Browser MMO Tutorial

Post by Tim »

Has anyone been able to integrate the phpFreeChat software (http://www.phpfreechat.net/]found here) with the Browser MMO tutorial?

I am currently working on it but am running into issues carrying the username over to the chat script. I think this is a must so someone doesn't join the chat room and /nick Tim and pretend they are me if I'm not there.

Changing

Code: Select all

$params["nick"] = "guest";
to

Code: Select all

$params["nick"] = $username;
doesn't work.

Just looking for some assistance with this. If successful I will update this post and give a tutorial on how we got it working for all the users wanting to get a chat room on their game.

Thanks!
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: phpFreeChat & Browser MMO Tutorial

Post by hallsofvallhalla »

Where is $username coming from? Session? Do you have session start?
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: phpFreeChat & Browser MMO Tutorial

Post by Jackolantern »

I am assuming that code is coming from a FreeChat script, and not a PBBG script. Like Halls asked, where is $username coming from? If you do add your session_start code to it, and actually pull the $username variable out of the $_SESSION global array, you should be able to pull it over to that script fairly easily.

EDIT: Some difficulty may come from having to go all through the Freechat scripts and make sure you are enforcing the connection all the way through, or some large holes could be formed. Not that I am familiar at all with FreeChat, however. If that is the only place where the username comes in to play, this would be a very good candidate for other devs here wanting a chat system in the tutorial game.
The indelible lord of tl;dr
Tim
Posts: 37
Joined: Fri Jun 10, 2011 12:49 am

Re: phpFreeChat & Browser MMO Tutorial

Post by Tim »

Yes, here is the upper portion of the index.php of the chat directory.

Code: Select all

<?php
session_start();
include_once '../connect.php';
include_once '../session.php';

require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Quick chat";
$params["nick"] = $username;
$params['firstisadmin'] = true;
//$params["isadmin"] = true; // makes everybody admin: do not use it on production servers ;)
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$chat = new phpFreeChat( $params );
When I add the includes for session start, connect.php, and session.php it gets stuck on:

Code: Select all

Chat loading ...
Please wait
I will continue looking through the other .php files and see if there are any other instances of "nick" that might be causing problems.

EDIT:

I found the following code in ../chat/src/pfcglobalconfig.class.php

Code: Select all

  /**
   * <p>If you have already identified the user (forum, portal...) you can force the user's nickname with this parameter.
   * Defining a nick will skip the "Please enter your nickname" popup.</p>
   * <p>Warning : Nicknames must be encoded in UTF-8.
   * For example, if you get nicks from a databases where they are ISO-8859-1 encoded,
   * you must convert it: <code>$params["nick"] = iconv("ISO-8859-1", "UTF-8", $bdd_nickname);</code>
   * (Of course, change the <code>$bdd_nickname</code> parameter for your needs.)</p>
   * <p>(Default value: "" - means users must choose a nickname when s/he connects.)</p>
   */
  var $nick = "";
I believe this is where I would put the

Code: Select all

include_once '../../session.php';
and change the code to

Code: Select all

  var $nick = $username;
but it's giving me the following error

Code: Select all

Warning: include_once(../../session.php) [function.include-once]: failed to open stream: No such file or directory
The structure is /public_html/game/chat/
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: phpFreeChat & Browser MMO Tutorial

Post by 62896dude »

Not sure if my idea will work, but try keeping every file in just one folder. That way, you only need to call for session.php, and not /../../session.php
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Tim
Posts: 37
Joined: Fri Jun 10, 2011 12:49 am

Re: phpFreeChat & Browser MMO Tutorial

Post by Tim »

62896dude wrote:Not sure if my idea will work, but try keeping every file in just one folder. That way, you only need to call for session.php, and not /../../session.php
phpFreeChat is 553 different files. Could get pretty messy if I have everything in one folder. I can't figure out why ../../session.php won't work.

EDIT:

It looks like this works for some reason (doesn't give me errors).

Code: Select all

session_start();
include_once '../connect.php';
include_once '../session.php';
When I add the above code though, the chat system displays

Code: Select all

Chat loading ...
Please wait
and never loads. When I remove it, it loads fine.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: phpFreeChat & Browser MMO Tutorial

Post by Jackolantern »

Does your session.php file actually get the value out of the session global and assign it to $username?
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”