koraktor / steam-condenser

A multi-language library for querying the Steam Community, Source, GoldSrc servers and Steam master servers
https://koraktor.de/steam-condenser
Other
359 stars 65 forks source link

CS:GO Server and Logging #262

Closed Nils001 closed 9 years ago

Nils001 commented 9 years ago

Hi, im quite new to Steam Condenser and i do Java for 2 Years in School. I wanted to create a new csgo Server with this code

try{
                nils = new SourceServer(ip,27243);
                nils.initSocket();
                System.out.println("OK !");
            }catch(Exception e)
            {
                System.out.println(e);
            }

The Object ip is an InetAddress. I get this error : java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

And is there a Kind of Tutorial how to get the log ? Because i want to make a Simple RCON Tool for private use and don't know how to enable it.

P.S. Im German

koraktor commented 9 years ago

Can you please provide the full stack trace for that error?

Nils001 commented 9 years ago

Ehh Don`t laugh about me but im currently programming in BlueJ. I'm looking at some Tutorial to learn how to work with eclipse.

my code is

import java.net.*;
import java.net.InetAddress;
import com.github.koraktor.steamcondenser.*;
import com.github.koraktor.steamcondenser.steam.*;
import com.github.koraktor.steamcondenser.steam.sockets.*;
import com.github.koraktor.steamcondenser.steam.servers.*;
import com.github.koraktor.steamcondenser.steam.packets.*;
import com.github.koraktor.steamcondenser.steam.packets.rcon.*;
import com.github.koraktor.steamcondenser.steam.community.*;

import com.github.koraktor.steamcondenser.exceptions.*;
public class Server
{
    private SourceServer nils ;
    private InetAddress ip;
    public Server()
    {
        try{
            InetAddress ip = InetAddress.getByName("46.174.49.27");
            System.out.println(ip);
        }catch(Exception e)
        {
            System.out.println(e);
        }
        try{
                nils = new SourceServer(ip,27243);
                nils.initSocket();
                System.out.println("OK !");
            }catch(Exception e)
            {
                System.out.println(e);
            }

        try{
        nils.rconAuth("");
        System.out.println("OK !");
        }catch(Exception e)
        {
        System.out.println(e);
        }
        try{
        System.out.println(nils.getPing());
        System.out.println("OK !");
        }catch(Exception e)
        {
        System.out.println(e);
        }
        }

    }

I just try to create a object and i get this system.out.print:

/46.174.49.27
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.lang.NullPointerException
java.lang.NullPointerException
Nils001 commented 9 years ago

I think it is a error of mine but i cant figure out which the InetAddress thing works but the creation of the object SourceServer does not work .. whyever

koraktor commented 9 years ago

Try using

e.printStackTrace();

inside your catch blocks to get the stack trace. That way you can see the real reason for that error.

It may be a bug.

Nils001 commented 9 years ago

http://puu.sh/eUZJv/e08fa0194b.png this is my console i dont know why i does not print the stacktrace

koraktor commented 9 years ago

Please re-check the code in my previous comment. I had the wrong line in there.

Nils001 commented 9 years ago
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:653)
    at java.util.ArrayList.get(ArrayList.java:429)
    at com.github.koraktor.steamcondenser.steam.servers.Server.<init>(Server.java:80)
    at com.github.koraktor.steamcondenser.steam.servers.GameServer.<init>(GameServer.java:64)
    at com.github.koraktor.steamcondenser.steam.servers.SourceServer.<init>(SourceServer.java:108)
    at Server.<init>(Server.java:27)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at bluej.runtime.ExecServer$3.run(ExecServer.java:746)
java.lang.NullPointerException
    at Server.<init>(Server.java:37)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at bluej.runtime.ExecServer$3.run(ExecServer.java:746)
java.lang.NullPointerException
    at Server.<init>(Server.java:45)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at bluej.runtime.ExecServer$3.run(ExecServer.java:746)
Nils001 commented 9 years ago

the nullpointers are there because i have no server object, i think.

koraktor commented 9 years ago

Ok, found the reason. The check here is wrong for your use case.

You can workaround this by using the following to create the server object:

new SourceServer("46.174.49.27", 27243);
Nils001 commented 9 years ago

Ok thanks. Can i open a new ticket because of the log ? Or do i have any possibility to reach you privately ? In German of course.

koraktor commented 9 years ago

Via mail, see the README. Feel free to open up a ticket if you think you've found a bug, though.

koraktor commented 9 years ago

Ok, this isn't a bug. I didn't realize your mistake.

Your initial code did assign the InetAddress to a local variable ip, but you create the SourceServer with the instance variable ip of your Server class which is null. So you're effectively calling new SourceServer(null, 27243).

Nils001 commented 9 years ago

Ohh i see my mistake so i only have to remove the InetAddress in the constructor, right ?

koraktor commented 9 years ago

Just reuse the instance variable, there's no need to declare another one.