Player Boolean Flags.

For all mod-related questions and custom code.
Post Reply
User avatar
OfficerFlake
Offline
Posts: 25
Joined: May 28th, 2012, 12:03 am

Player Boolean Flags.

Post by OfficerFlake »

Okay... I'm trying to modify IRC.cs into an elegent solution for users of the server. On by default, but it can be ignored.

but the hard part is modding the playerinfo flags to have an "IgnoringIRC" switch.

1) How do I add the flag to PlayerInfo?
2) How do I read and write this flag?

I'm looking for a "if (PlayerInfo.Playername.IgnoringIRC)"... style equivilent.
and for the switch: "PlayerInfo.Playername.IgnoringIRC = !PlayerInfo.Playername.IgnoringIRC"

I'm New to C#, but I'm not new to coding (I'm pretty decent at Python.)

The hardest part for me is learning fcrafts structure and where things are defined, read, and written (for eg: where is the player data loaded from the playerdb?).

I really want to learn to mod fcraft because it's very powerful and has a lot of potential for what I want to create.

Thanks folks.

- OfficerFlake
=== MeinKraft 24/7 ===
Server Owner & Code Developer

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: Player Boolean Flags.

Post by fragmer »

PlayerInfo objects are saved to PlayerDB.txt files, one line per player. Basically it's a variant CSV/comma-separated-values flatfile. I usually advise people against adding fields to their copies of fCraft. If you add a field, and I later add another field to an official release of fCraft, it would conflict with your code.

If you still want to proceed, you'll need to add a new property to the PlayerInfo object, then modify PlayerDB serialization (saving) and loading code. All this code is contained in file /fCraft/Player/PlayerInfo.cs

Properties are at the top. Loading code is in "Loading" region, ~360 lines down - "LoadFormat2" method. Saving code is ~785 lines down - "Serialize" method.

User avatar
OfficerFlake
Offline
Posts: 25
Joined: May 28th, 2012, 12:03 am

Re: Player Boolean Flags.

Post by OfficerFlake »

I think I worked it out... I don't need it to save, just be temporary. So best add it to "player.cs" instead correct?

all I do is define the variable, set it on connect, and read it as <Player name> then name.IRCconnecting...

I think I'm right. I'll give it a go.

EDIT: Yep. that works fine. I need to modify SendSay to make a SendIRC and SendInternal to SendInternalIRC for IRC ignore handling and to have IRC be able to be sent without a players name attached. :D

Lessons learnt: Apply Boolean flags to player.cs and not playerinfo.cs. They are best written on connection, and are best read via Player player -> player.<BOOLEANFLAG>

I'm using a list of Server.Players then iterating over it with foreach and testing each players irc setting.. it's quick enough for irc messages.

Thanks for the help fragmer.
=== MeinKraft 24/7 ===
Server Owner & Code Developer

Post Reply