- Home /
Query not found-masterserver.requesthostlist
Hi guys I am using masterserver.requesthostlist and I keep getting the error that the gametype or for me the serverName isn't found. I am using:
Public game object derp; MasterServer.RequestHostList(derp.GetComponent().serverName);
serverName is a string the player enters before the server is even registered, when people hit the join button then the above code begins running so I was wondering if there was a fix to this issue. Thank You, Kingofweirdos
If you do not understand just write a comment and also @LukasLicek can u look at this, Thank You
@$$anonymous$$ingofweirdos, could you please add the script with serverName ? I may will edit my answer afterwards :)
Answer by LukasLicek · Jan 09, 2018 at 02:35 PM
Hello @Kingofweirdos , I did look into your code and maybe I have found the source of your problem.
I got the same error when I was trying to connect trying to connect via server name, but I should have use GameType. I think that you are trying to connect via server name, but you should use GameType. I've written a simple code, which should demonstrate that:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Networking;
public class TestScript : MonoBehaviour {
public string UniqueGameType;
public string serverName;
public string comment;
void OnMasterServerEvent(MasterServerEvent masterserverevent){
if (masterserverevent == MasterServerEvent.RegistrationSucceeded) {
Debug.Log ("RegistrationSucces");
//WEIRD LINE
MasterServer.RequestHostList (UniqueGameType);
}
}
void OnGUI() {
if (GUILayout.Button ("Start Server"))
{
MasterServer.ClearHostList();
// Use NAT punchthrough if no public IP present
Network.InitializeServer(32, 25002, !Network.HavePublicAddress());
MasterServer.RegisterHost(UniqueGameType, serverName, comment);
}
if (GUILayout.Button ("Connect"))
{
Debug.Log ("Requesting server: " + UniqueGameType);
MasterServer.RequestHostList (UniqueGameType);
HostData[] hostData = MasterServer.PollHostList();
Debug.Log ("Number of servers: "+hostData.Length);
//write server info to console
if (hostData.Length > 0) {
Debug.Log ("Requesting name: " + hostData [0].gameName);
Debug.Log ("Requesting type: " + hostData [0].gameType);
Debug.Log ("Requesting ip: " + hostData [0].ip);
}
}
}
}
Another issue is your idea with loading scenes. I think, that maybe when you load them, Unity will not execute registering host, because it takes a while and you load next scene, before it can finish.
Please take in account, that I dont work with HLAPI and Networking very often. So, for Ex. I have to RequestHostList two times in my code. (Extra request commented as WEIRD LINE :D). That being said, I hope I've helped you and good luck :)
@LukasLicek I am using the following code in order to make the master server I don't think it is a a problem with the derp.getcomponent().serverName; I am currently testing I will update you through a further comment.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Scene$$anonymous$$anagement;
public class TestScript : $$anonymous$$onoBehaviour {
public HostData[] hostData;
public bool create;
public bool joining;
public string serverPassword;
public string playerName;
public string clientPassword;
public Vector2 scrollPosition;
public Button createbutton;
public Button joinbutton;
public InputField playerNameInput;
public InputField serverNameInput;
public string serverName;
public InputField serverInfoInput;
public string serverInfo;
public Button makebutton;
public Button backbutton;
public InputField serverPasswordInput;
public static string serverNameStatic;
void ServerInfo1(){
if (serverInfoInput.text == "") {
serverInfoInput.placeholder.GetComponent<Text>().text = "Please Enter Server Info";
}
else{
serverInfo = serverInfoInput.text;
}
}
void ServerName1(){
if (serverNameInput.text == "") {
serverNameInput.placeholder.GetComponent<Text>().text = "Please Enter A Server Name";
}
else{
serverName = serverNameInput.text;
}
}
void $$anonymous$$akeServer(){
if (serverName == "") {
serverNameInput.placeholder.GetComponent<Text> ().text = "Please Enter A Server Name";
}
if (serverInfo == "") {
serverInfoInput.placeholder.GetComponent<Text>().text = "Please Enter Server Info";
}
else {
serverStart ();
}
}
void ServerPassword() {
if (serverPasswordInput.text == "") {
serverPasswordInput.placeholder.GetComponent<Text>().text = "Please Enter Password Info";
}
else {
serverPassword = serverPasswordInput.text;
}
}
void Back(){
Scene$$anonymous$$anager.LoadScene ("Second");
create = false;
joining = false;
}
void Create () {
create = true;
Scene$$anonymous$$anager.LoadScene ("Creating");
}
void OnEnable(){
Scene$$anonymous$$anager.sceneLoaded += OnSceneLoaded;
}
void OnSceneLoaded(Scene scene, LoadScene$$anonymous$$ode mode){
if(scene.name.Contains("Joining")){
$$anonymous$$asterServer.RequestHostList (serverName);
}
}
void Join () {
joining = true;
Scene$$anonymous$$anager.LoadScene ("Joining");
}
void PlayerName()
{
playerName = playerNameInput.text;
}
void serverStart(){
if (serverPassword != "") {
Network.inco$$anonymous$$gPassword = serverPassword;
}
Network.InitializeServer(15,25001, !Network.HavePublicAddress());
$$anonymous$$asterServer.RegisterHost(serverName, playerName, serverInfo);
}
void On$$anonymous$$asterServerEvent($$anonymous$$asterServerEvent masterserverevent){
if (masterserverevent == $$anonymous$$asterServerEvent.RegistrationSucceeded) {
Scene$$anonymous$$anager.LoadScene ("Lobby1");
}
}
}
@LukasLicek I forgot to type the portion in the original portion of the question I can understand where the confusion came from
Answer by Bunny83 · Jan 10, 2018 at 11:41 AM
Since this question somehow get constantly bumped i want to clear up some things here.
First of all the MasterServer is part of the legacy networking system (RakNet). It's still in the engine but has nothing to do with the new UNet system. The legacy system shouldn't be used for new projects.
Furthermore as far as i know Unity has shut down the default development MasterServer they used to host on their own server. So you have to host and use your own MasterServer build. That also means you have to know the IP and port of your masterserver and have to set them. This was always necessary even back then when RakNet was the active networking engine. The development Masterserver which was hosted by Unity was only meant for development testing.
People also seem to confuse what the "GameType" parameter is good for. The point here is that a single MasterServer could handle servers for many different games at once. The GameType is a filtering string. This string should be constant and unique to your game. RequestHostList can only return servers which has been registrated with the exact same gametype string. Think about it like Valves source engine. The "gametype" would be something like "TeamFortress2", "HalflifeDM", "Left4Dead", ... So the server browser only shows servers which actually run the desired game.
Next you have to keep in mind that "RequestHostList" is an asynchronous request. It can take several seconds until you actually received the host list and it doesn't have to arrive at once. That's why you have to continously call PollHostList() to actually get new results which you should display in a list.
Finally keep in mind that the server who registered itself to the master server is a seperate entity from players which request the host list who wants to join a server. Information typed in by the server creator is not available to other clients. If you use a user typed in "gametype" to register the server, the clients which want to join the server would need to type in the exact same string or the master server won't return anything. Allowing user gametypes would however cause some problems. When two server creators use the same string (e.g. "MyServer"), all clients which want to join "MyServer" would see those two servers.
Debugging network related issues is really hard from the outside. It's already quite complicated when you directly work with it as there are many different things which can go wrong. From the information given we can't deduce what might be the issue here.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Multiplayer Respawning Problems 0 Answers
How to make a simple co-op (2-player) Game? 1 Answer
Code Wont Work? 0 Answers