Author Topic: How to get a channel list  (Read 13413 times)

inewland53

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: How to get a channel list
« Reply #15 on: May 24, 2014, 05:18:36 PM »
I was running into a read error when trying to get the Player Limit as well. In order to get a ushort from the BinaryReader you need to use this code:

  1. int playerLimit         = reader.ReadUInt16();   // Don't use ReadInt32();
  2.  

Hope that helps someone.

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: How to get a channel list
« Reply #16 on: October 17, 2015, 07:08:23 PM »
  1. void OnChannelList(Packet response, BinaryReader reader, IPEndPoint source)
  2.     {
  3.         Console.AddMessage("Fetching Room List...");
  4.  
  5.         int count = reader.ReadInt32();
  6.  
  7.         for (int i = 0; i < count; ++i)
  8.         {
  9.             int channelID = reader.ReadInt32();
  10.             int playerCount = reader.ReadInt32();
  11.             bool password = reader.ReadBoolean();
  12.             bool isPersistent = reader.ReadBoolean();
  13.             string level = reader.ReadString();
  14.             string channelName = reader.ReadString();
  15.  
  16.             print(playerCount);
  17.         }
  18.  
  19.         Console.AddMessage("Fetched Room List");
  20.     }

From this code you can see that I should get a message in my Unity console containing the number of players in a channel.
For some reason I get rediculous 6 digit numbers instead of the amount of players in a channel.

Example: 1 player connected to a room is supposed to print "1". Instead I get this: "589825"

Please help :P

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: How to get a channel list
« Reply #17 on: October 18, 2015, 01:56:17 AM »
TNPacket.cs
line #306-319

you are reading an "int" when it should be "ushort"...

this problem was addressed many times on page 1 of this thread.

  1. /// <summary>
  2. /// List open channels on the server.
  3. /// int32: number of channels to follow
  4. /// For each channel:
  5. ///   int32: ID
  6. ///   ushort: Number of players
  7. ///   ushort: Player limit
  8. ///   bool: Has a password
  9. ///   bool: Is persistent
  10. ///   string: Level
  11. ///   string: Custom data
  12. /// </summary>
  13.  
  14. ResponseChannelList,
  15.  

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: How to get a channel list
« Reply #18 on: October 18, 2015, 06:19:13 AM »
Thanks! This seems to have solved my problem :)

However now I just want to know. What is the difference between, int, int16, int32, int64, uint16, uin32 and uint64..   ???

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to get a channel list
« Reply #19 on: October 18, 2015, 06:53:15 PM »
The difference is size in bytes. Int16 is 16 bits (2 bytes). Int32 is 32 bits (4 bytes) and Int64 is 64 bits (8 bytes).

You were trying to read too much data from the stream.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: How to get a channel list
« Reply #20 on: October 18, 2015, 08:05:55 PM »
Thanks! This seems to have solved my problem :)

However now I just want to know. What is the difference between, int, int16, int32, int64, uint16, uin32 and uint64..   ???

id rather not post this here, but its a nice reference:

  1. C# Type                 .NET Framework Type             mySQL                                           Range
  2. ---------------------------------------------------------------------------------------------------------------------
  3.  
  4. bool                    System.Boolean                  tinyint(1)
  5.  
  6. byte                    System.Byte                     tinyint(3) unsigned                     0 to 255
  7. sbyte                   System.SByte                    tinyint(3)                              -128 to 127
  8. short                   System.Int16                    smallint(5)                             -32,768 to 32,767
  9. ushort                  System.UInt16                   smallint(5)     unsigned                0 to 65,535
  10. int                     System.Int32                    int(11)                                 -2,147,483,648 to 2,147,483,647
  11. uint                    System.UInt32                   int(11) unsigned                        0 to 4,294,967,295
  12. long                    System.Int64                    bigint(20)                              –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  13. ulong                   System.UInt64                   bigint(20) unsigned                     0 to 18,446,744,073,709,551,615
  14.