Forum Multiplayer player.ConnectUserId is always null !!!! plz help

Discussion and help relating to the PlayerIO Multiplayer API.

player.ConnectUserId is always null !!!! plz help

Postby mouldi » August 18th, 2014, 1:03 am

Hi, guys i'm working on my FPS for 2 years now it's fb+photon+playerio all with unity c#, every thing is great so far until this happened the playeer proprety ConenctUserid is showing nothing on the console (local server test app) it was working before i refactered my code and here's what i did but i can't fix it so please bear me and try to help me :)

i used to have all the code in 1 game.cs file then i had to extend the thing and refactor it because i have my types of rooms in my fps game that's a reason and for more other raisons, anyway the point is i created an assembly i named BulletRush, and i started refactering the code the player class is the folowwing in a Player.cs file :

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using PlayerIO.GameLibrary;
using System.Drawing;



namespace BulletRush
{
public class Player : BasePlayer{


public Player()
{
Console.WriteLine("this is player class constructor");
}


//player personal info :

public string playername { get; set; }
public string nickname { get; set; }
public string email { get; set; }
public string password { get; set; }
public int fbid { get; set; }

//player match data :

public int level { get; set; }
public int totalscore { get; set; }
public int xp { get; set; }
public int totalxp { get; set; }
public int score { get; set; }


public DatabaseArray items { get; set; }
public DatabaseArray medals { get; set; }
public DatabaseArray ranks { get; set; }
public bool alive { get; set; }
public int hp { get; set; }
public int armor { get; set; }
public int team { get; set; }
public int totalkills { get; set; }
public int totaldeaths { get; set; }




}
}

* and here the Lobby.cs file all in the same assembly under the same namespace :
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using PlayerIO.GameLibrary;
using System.Drawing;
using Procurios.Public;


namespace BulletRush
{



[RoomType("Lobby")]
public class Lobby : Game<Player>
{

public Player player = new Player();
public List<Item> items = new List<Item>();
public int[] attachements1 { get; set; }

// public Weapon weapon2;
public int[] attachements2 { get; set; }

public int[] charattachements { get; set; }

public int[] bombs { get; set; }




void GenItems()
{
Console.WriteLine("Generating the items");
items = ItemJsonParser();

}


List<Item> ItemJsonParser()
{

bool success = false;
JSON jsonHelper = new JSON();
Hashtable objhash = new Hashtable();
String objString = System.Text.Encoding.UTF8.GetString(EmbeddedResource.GetBytes("items.json"));

objhash = (jsonHelper.JsonDecode(objString, ref success)) as Hashtable;

ArrayList objarray = objhash["items"] as ArrayList;
List<Item> listofobj = new List<Item>();



foreach (Hashtable item in objarray)
{
Item itemtofill = new Item();
foreach (DictionaryEntry field in item)
{

switch (field.Key.ToString())
{
case "id": itemtofill.id = Convert.ToInt32(field.Value);

// Debug.Log("id from class item" + itemtofill.id);
break;
case "name": itemtofill.name = (string)field.Value;
// Debug.Log(itemtofill.name);
break;
case "type": itemtofill.type = (string)field.Value;
// Debug.Log(itemtofill.type);
break;
}
listofobj.Add(itemtofill);

}


}

return listofobj;
}





private ArrayList rooms = new ArrayList();


private void initItems(Player player)
{
Console.WriteLine("player joined " + player.Id);
Console.WriteLine("player joined " + player.ConnectUserId);
Console.WriteLine("player joined with name" + player.nickname);
}

public override void GameStarted()
{

player.nickname = "mouldi";
initItems(player);
Console.WriteLine("player joined from gamestarted" + player.ConnectUserId);
// items = JSON(itemsJSON);
//Console.WriteLine(items.ToString() + items.Count);
PreloadPlayerObjects = true;

// This is how you setup a timer
AddTimer(delegate
{
// code here will code every 100th millisecond (ten times a second)
}, 100);

// Debug Example:
// Sometimes, it can be very usefull to have a graphical representation
// of the state of your game.
// An easy way to accomplish this is to setup a timer to update the
// debug view every 250th second (4 times a second).
AddTimer(delegate
{
// This will cause the GenerateDebugImage() method to be called
// so you can draw a grapical version of the game state.
RefreshDebugView();
}, 250);
}

// This method is called when the last player leaves the room, and it's closed down.
public override void GameClosed()
{
Console.WriteLine("user left " + player.Id);

}

// This method is called whenever a player joins the game
public override void UserJoined(Player player)
{


// this is how you send a player a message


// this is how you broadcast a message to all players connected to the game
Broadcast("UserJoined", player.Id);
}

// This method is called when a player leaves the game
public override void UserLeft(Player player)
{

Broadcast("UserLeft", player.Id);
Console.WriteLine("user left " + player.ConnectUserId);
}

// This method is called when a player sends a message into the server code

public void BroadcastOthers(Player player, Message m)
{
foreach (Player p in Players)
{
if (p != player)
p.Send(m);
}
}


private void createRoom(Player player, Message message)
{
Room room = new Room();
room.id = 12132;
room.name = message.GetString(0);
room.map = message.GetInt(1);
room.mode = message.GetInt(2);
room.max = message.GetInt(3);
room.players = new ArrayList();
room.players.Add(player);
message.Add(room.id, player.ConnectUserId);

// broadcast room info to all players
Broadcast("roomCreated", message);
}

private void joinRoom(Player player, Message message)
{


}



}

public struct Room
{
// room id
public int id;
public string name;

// room desc
public int map;
public int mode;
public int max;

// room players
public ArrayList players;

}



}

* as u can see in the gamestarted() default method i loged the following line:
Console.WriteLine("player joined " + player.ConnectUserId);
* what i get in the console is the following :
player joined
* that's all !!!! it can't log the connenct user id !!!!

* now the strange about this if you look at the code up you find me in the startgame method i'm doing the following:
player.nickname = "mouldi";
*and then i log the "player.nickname"
and i get a perfect result "mouldi".
that mean there is nothing wrong with my class Player which ofcaurse inherit from baseplayer !!!

Any clue or idea or anything please i need some help here ?

Thanks buys :)
Mouldi
mouldi
 
Posts: 23
Joined: December 28th, 2012, 2:02 am

Return to Multiplayer