Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Server side: get offline players IP address


Zamin
 Share

Recommended Posts

The IP of the player is lost upon disconnecting, so you can't really retrieve an IP that doesn't exist. However, you can make it so that the most recent IP is stored with the player. This is very easy to do.

In your server, go into modTypes. In here, you'll find all the structures for containing most of the game data for things like NPCs, resources, and players. Look for 

```

Public Type PlayerRec
```
Everything in between that and

```

End Type

```
contains properties of the player.

Go to the bottom of the PlayerRec, and type something like

```

LastKnownIP as String

```
Now go to modPlayer and look for the sub

```

Sub LeftGame(ByVal index As Long)

```
and replace this

```

' save and clear data.
Call SavePlayer(index)
Call SaveBank(index)
Call ClearBank(index)

```
with this

```

' save and clear data.
Player(index).LastKnownIP = GetPlayerIP(index)
Call SavePlayer(index)
Call SaveBank(index)
Call ClearBank(index)

```
The sub SavePlayer will pull all data within the PlayerRec to a file, and it will load it up when the server starts. Enjoy! ^_^
Link to comment
Share on other sites

Thanks guys,

That's a great tutorial Matt, this is a great learning experience for me. I can definitely take what you have above, and maybe create a file or Usernames with last-known-IPs.

I was thinking of taking this to the next level. in the server/data/accounts folder, all account files are saved. Correct me if I'm wrong, the username and password are both saved in the .bin files for each user. I haven't look at it myself yet to be honest, but I would like to end up at a place where I also store the last-known-ip of the account in this .bin file. I am sure this is possible as we already save the username and password. What are your thoughts?

Edit: I apologize for the late reply, I got sidetracked
Link to comment
Share on other sites

The subs that handle saving player data collect all data in the PlayerRec save it to the .bin file.

```

Sub SavePlayer(ByVal index As Long)
Dim filename As String
Dim F As Long

filename = App.path & "\data\accounts\" & Trim$(Player(index).Login) & ".bin"

F = FreeFile
Open filename For Binary As #F
Put #F, , Player(index)
Close #F

End Sub

```
Same thing goes for loading player data. So just by adding a new value to the PlayerRec, it will automatically save and load both to and from the player.bin file without you have to make a statement like

```

Put #F, , Player(index).LastKnownIP
```
Link to comment
Share on other sites

~~Thanks for the reply Matt.~~

~~There is something missing here…~~

~~As soon as i put 'LastKnownIp As String' in playerRec….the client just loads and loads, it doesn't open. I think we're missing a step~~

EDIT:

OK, I left the above text just for reference, i got it working though. This is how…

Defined a new variable in PlayerRec as you said. But by updating the LastKnownIP at LeftGame() (only runs when player is leavingthe game) causes issues. When player is first coming into the game and does not have the LastKnownIP value in the account.bin file, it crashes. So I am getting the players LastKnownIP in method JoinGame() instead. :)

I have more questions though.

What do I need to do to make sure that at client side, when I do **Player(index).Login** that it gives me the players login (not the char name). Similar to what we do in client side when we need to get the players name and password, and IP.
Link to comment
Share on other sites

There are somethings that should never be kept client-side for security reasons. Usernames and passwords are one of them. 

Therefore you cannot just do Player(index).Login. You'll have to create a field called login and then send the username from the server to the client.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...