AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting ip + port from file (https://forums.alliedmods.net/showthread.php?t=222683)

AwesomeMan 08-05-2013 11:00

Getting ip + port from file
 
Hello, I want to get ip + port from file into different variables.
By that I mean, i have a file called "ips.txt" and on first line, its:
1.1.1.1:27015
I want to get 1.1.1.1 into a variable let's say ip
and 27015 into variable port.
So ip = 1.1.1.1
port = 27015
Note that i will have more than one ip in file. an example:
1.1.1.1:27015
1.2.3.4:27055
PHP Code:

    new filepointer fopen(filename,"r")
    if(
filepointer)
    {
        new 
parsedip[32]
        new 
readdata[128]
        
        while(
fgets(filepointer,readdata,127))
        {
            
parse(readdata,parsedip,31)
        }
        
fclose(filepointer)
    } 

This is all i could get from reading tutorials.

fysiks 08-05-2013 11:34

Re: Getting ip + port from file
 
I would use strtok().

Out of curiosity, what are you using the IPs for? I can't think of any good use for an IP.

AwesomeMan 08-05-2013 11:40

Re: Getting ip + port from file
 
Quote:

Originally Posted by fysiks (Post 2006231)
I would use strtok().

Out of curiosity, what are you using the IPs for? I can't think of any good use for an IP.

Thanks, I will use strtok. If I have any issue i will post.
Hmm, Im doing it purely for experience. Im still learning and i want to improve.

fysiks 08-05-2013 11:47

Re: Getting ip + port from file
 
Quote:

Originally Posted by AwesomeMan (Post 2006237)
Thanks, I will use strtok. If I have any issue i will post.
Hmm, Im doing it purely for experience. Im still learning and i want to improve.


It's such a small function that a tutorial would not be appropriate for that function alone. However, the function is well documented in the include files:

http://hg.alliedmods.net/amxmodx-cen...tring.inc#l154

If you are trying to learn, I suggest that you don't do anything with IPs (because there is no good use for them). If you want to work with something that uniquely identifies a player, work with SteamIDs.


All times are GMT -4. The time now is 15:47.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.