These are chat archives for ikkentim/SampSharp

26th
Sep 2016
Florian van Dillen
@fvandillen
Sep 26 2016 12:17
When implementing IPermissionChecker, I want to use my own Player class in the check method due to some data in the account system i'm using. How would I go about that?
Tim Potze
@ikkentim
Sep 26 2016 12:17
var myPlayer player as Player;
Florian van Dillen
@fvandillen
Sep 26 2016 12:17
Tim Potze
@ikkentim
Sep 26 2016 12:18
oh better yet
simply also add
bool IPermissionChecker.Check(BasePlayer player)
{
    return Check(player);
}
next to your Check(Player player) implementation
Florian van Dillen
@fvandillen
Sep 26 2016 12:19
overload it lol
Tim Potze
@ikkentim
Sep 26 2016 12:19
this is not an overload :)
Florian van Dillen
@fvandillen
Sep 26 2016 12:19
Please enlighten me :)
Tim Potze
@ikkentim
Sep 26 2016 12:19
this is an explicit interface implementation
Florian van Dillen
@fvandillen
Sep 26 2016 12:21
It does complain about that though
Tim Potze
@ikkentim
Sep 26 2016 12:21
oh yes sorry you do still need to cast it, or ‘as’ it
player as Player
Florian van Dillen
@fvandillen
Sep 26 2016 12:22
That seems to work just fine
However when activating the permission checker on the command method, it says this
Tim Potze
@ikkentim
Sep 26 2016 12:26
:| shakes head
my bad
https://puu.sh/ron3g/298910b774.png did I even test this?
Should be Type
Florian van Dillen
@fvandillen
Sep 26 2016 12:26
lel
Tim Potze
@ikkentim
Sep 26 2016 12:27
Will fix in the evening
Florian van Dillen
@fvandillen
Sep 26 2016 12:27
Sure, no rush
Florian van Dillen
@fvandillen
Sep 26 2016 12:41
Also seem to be getting NullReference errors when handling events
Tim Potze
@ikkentim
Sep 26 2016 12:43
is an exception from your own login controller
in LoginController.OnPlayerConnected
Florian van Dillen
@fvandillen
Sep 26 2016 12:45
I suppose it originates from this (which I do in both event handlers)
var player = sender as Player;
However that should be perfectly fine
Tim Potze
@ikkentim
Sep 26 2016 12:46
try logging the value of sender before casting? see what happens
Florian van Dillen
@fvandillen
Sep 26 2016 12:46
Aight, will try
It does log correctly
[14:47:34] RockStars6.RS6Account.LoginController - Player(Id:0, Name:=AV=Marcel)
Tim Potze
@ikkentim
Sep 26 2016 12:48
:/
Florian van Dillen
@fvandillen
Sep 26 2016 12:48
Exception occurs after that
Tim Potze
@ikkentim
Sep 26 2016 12:49
In your server folder
in the mono/etc/ somewhere is a pdb2mdb.exe
run it with mono mono pdb2mdb.exe path/to/pdb/file
if you do not have mono installed i think there is a mono.exe somewhere in the mono folder as well
then you get line numbers in your exceptions
hmm there is no mono.exe in the /mono folder :/
You’d have to download mono for that. I should have left it in there...
or maybe the pdb2mdb.exe will work with .net. not sure
Florian van Dillen
@fvandillen
Sep 26 2016 12:52
Nope, depends on mono
Tim Potze
@ikkentim
Sep 26 2016 12:53
:/ In 0.6 i had this symbols file conversion build into the plugin… but it crashed alot
if you do not want to install it, you can use Process.Start from your gamemode:)
Then relaunch the gammode afterwards
Florian van Dillen
@fvandillen
Sep 26 2016 12:57
It doesn't like it
Tim Potze
@ikkentim
Sep 26 2016 12:57
oh sorry you need to specify the path to the dll, not the pdb
Florian van Dillen
@fvandillen
Sep 26 2016 12:58
A wild .mdb appeared!
Tim Potze
@ikkentim
Sep 26 2016 12:58
Whoop!
You need to create one after compiling the dll or the mdb will be outdated. I’ll look into automation of this process later
Florian van Dillen
@fvandillen
Sep 26 2016 12:59
Okay now this is weird
var player = sender as Player;
It fails on that
Tim Potze
@ikkentim
Sep 26 2016 12:59
:|
Florian van Dillen
@fvandillen
Sep 26 2016 13:00
However, in the other method it fails on a completely different line
Tim Potze
@ikkentim
Sep 26 2016 13:00
I can’t do too much research atm since im at work :P
Florian van Dillen
@fvandillen
Sep 26 2016 13:00
It fails on lines 36 and 57
Nah, no rush lol
Tim Potze
@ikkentim
Sep 26 2016 13:01
wth those are weird lines to error on
Florian van Dillen
@fvandillen
Sep 26 2016 13:01
Especially because I used this code before
And it worked fine
Tim Potze
@ikkentim
Sep 26 2016 13:01
I really want to take another look into attaching debuggers
Florian van Dillen
@fvandillen
Sep 26 2016 13:01
The login controller itself hasn't changed a bit
Tim Potze
@ikkentim
Sep 26 2016 13:03
The mono soft debugger should be perfect for debugging.. hmm need to implement this
Florian van Dillen
@fvandillen
Sep 26 2016 19:11
Lol sounds pro
Anyway, been playing around a bit
What strikes me as odd is that about 10-15% of the times, the server doesn't shut down or hangs during shutdown
I have narrowed it down @ikkentim
Florian van Dillen
@fvandillen
Sep 26 2016 19:16
It hangs on either this.Log().Info(player.ToString()); or player.LoadAccount();
Tim Potze
@ikkentim
Sep 26 2016 19:16
gets to log 2 or not?
hmm
Florian van Dillen
@fvandillen
Sep 26 2016 19:17
Basically local variable player is null
It doesn't assign it somehow
Tim Potze
@ikkentim
Sep 26 2016 19:17
Which is odd because sender is Player
Florian van Dillen
@fvandillen
Sep 26 2016 19:17
Doesn't get to log 2
Yes
And the code isn't new
I used this exact same code before and it worked fine
Tim Potze
@ikkentim
Sep 26 2016 19:17
sender as Player does not perform any logic. It’s just a simple basic .net feature :/
Florian van Dillen
@fvandillen
Sep 26 2016 19:17
Under a previous version of the framework, to be precise
Hmm, would I need to cast it in a different way?
Tim Potze
@ikkentim
Sep 26 2016 19:19
this should work, but you can try printing sender is Player and you could try explicitly casting it (Player)sender. You could also try temporarily casting it to BasePlayer just to see if it works.
Florian van Dillen
@fvandillen
Sep 26 2016 19:23
Explicit casting throws InvalidCastException on the line where the cast is done
Cannot cast from source type to destination type
I'm suspecting something is wrong with the Player class itself, maybe?
Tim Potze
@ikkentim
Sep 26 2016 19:24
Then sender isn’t a Player instance
Print sender.GetType() ?
Florian van Dillen
@fvandillen
Sep 26 2016 19:24
Sec, doing it now
SampSharp.GameMode.World.BasePlayer
Tim Potze
@ikkentim
Sep 26 2016 19:25
:|
Did the Player type register properly?
If you attach a [PooledType] attribute to the Player class it should be done automatically
Florian van Dillen
@fvandillen
Sep 26 2016 19:26
Tim Potze
@ikkentim
Sep 26 2016 19:28
in server.cfg could you set loglevel to debug?
Florian van Dillen
@fvandillen
Sep 26 2016 19:28
Sure, sec
Tim Potze
@ikkentim
Sep 26 2016 19:28
see if the autoloading works
Florian van Dillen
@fvandillen
Sep 26 2016 19:28
Simply adding `loglevel debug to the cfg?
Tim Potze
@ikkentim
Sep 26 2016 19:28
yes
Florian van Dillen
@fvandillen
Sep 26 2016 19:30
Here we go:
Tim Potze
@ikkentim
Sep 26 2016 19:33
:|
I’m scanning for pooled types before loading controllers
Florian van Dillen
@fvandillen
Sep 26 2016 19:33
I guess that's a bad thing?:P
Tim Potze
@ikkentim
Sep 26 2016 19:34
so [PooledType] is processed, then overridded by types registered by controllers
Florian van Dillen
@fvandillen
Sep 26 2016 19:34
lol
Tim Potze
@ikkentim
Sep 26 2016 19:34
so BasePlayerController overrides this to BasePlayer
Should work the other way around.
Florian van Dillen
@fvandillen
Sep 26 2016 19:34
yup, because else the gamemode has no point
Tim Potze
@ikkentim
Sep 26 2016 19:34
I guess the temporary fix would be to create a subclass of BasePlayerController and handle it the old way for now
Controller autoloading should work just fine
Florian van Dillen
@fvandillen
Sep 26 2016 19:35
Okay let me quickly try that
Tim Potze
@ikkentim
Sep 26 2016 19:35
[AutoLoad] would work just right i think
Florian van Dillen
@fvandillen
Sep 26 2016 19:35
So make a class that does SomeClass : BasePlayerController ?
Tim Potze
@ikkentim
Sep 26 2016 19:35
Yes
[AutoLoad] should automatically load this controller in
Florian van Dillen
@fvandillen
Sep 26 2016 19:36
remove the [PooledType] for now?
Tim Potze
@ikkentim
Sep 26 2016 19:36
You can keep it but it’s overriden so effectively useless /shrug
Florian van Dillen
@fvandillen
Sep 26 2016 19:37
It doesn't recognize the [AutoLoad] attribute
Tim Potze
@ikkentim
Sep 26 2016 19:37
oh damn what did i call it
oh, it is [Controller]
Florian van Dillen
@fvandillen
Sep 26 2016 19:38
Should I put anything in the Custom Controller class?
Tim Potze
@ikkentim
Sep 26 2016 19:38
yes just above the class [Controller]public class FooController : /*…*/
I should have written the documentation when I worked on it… 🤷 ¯\(ツ)
Florian van Dillen
@fvandillen
Sep 26 2016 19:39
haha poor guy
[SampSharp:Debug] Autoloading type RockStars6.TempControllerFix... [SampSharp:Debug] RockStars6.TempControllerFix overrides SampSharp.GameMode.Controllers.BasePlayerController
Tim Potze
@ikkentim
Sep 26 2016 19:39
yup thats right
Florian van Dillen
@fvandillen
Sep 26 2016 19:40
Now testing the ingame stuff
Hoping it'll work
Tim Potze
@ikkentim
Sep 26 2016 19:40
yea me too :P
Florian van Dillen
@fvandillen
Sep 26 2016 19:40
Oh, explicit cast still not working, let's try the old way which was supposed to work in the first place
Same nullreference error
Tim Potze
@ikkentim
Sep 26 2016 19:42
:(
Would need to do some testing myself, but atm not on windows
Florian van Dillen
@fvandillen
Sep 26 2016 19:43
No rush though
Here's the two stack traces from OnPlayerConnect and OnPlayerRequestClass:
[connection] 127.0.0.1:54297 requests connection cookie.
[connection] incoming connection: 127.0.0.1:54297 id: 0
[join] =AV=Marcel has joined the server (0:127.0.0.1)
[21:42:00] RockStars6.RS6Account.LoginController - SampSharp.GameMode.World.BasePlayer
[SampSharp] Exception thrown during execution of OnPlayerConnect:
System.NullReferenceException: Object reference not set to an instance of an object
  at RockStars6.RS6Account.LoginController.OnPlayerConnected (System.Object sender, System.EventArgs e) [0x00025] in C:\Users\info\Desktop\Development\RS6\RockStars6\RockStars6\RS6Account\LoginController.cs:38
  at (wrapper delegate-invoke) System.EventHandler`1<System.EventArgs>:invoke_void_object_TEventArgs (object,System.EventArgs)
  at SampSharp.GameMode.BaseMode.OnPlayerConnected (SampSharp.GameMode.World.BasePlayer player, System.EventArgs e) [0x00000] in <filename unknown>:0
  at SampSharp.GameMode.BaseMode.OnPlayerConnect (Int32 playerid) [0x00000] in <filename unknown>:0
[SampSharp] Exception thrown during execution of OnPlayerRequestClass:
System.NullReferenceException: Object reference not set to an instance of an object
  at RockStars6.RS6Account.LoginController.OnPlayerRequestClass (System.Object sender, SampSharp.GameMode.Events.RequestClassEventArgs e) [0x00050] in C:\Users\info\Desktop\Development\RS6\RockStars6\RockStars6\RS6Account\LoginController.cs:60
  at (wrapper delegate-invoke) System.EventHandler`1<SampSharp.GameMode.Events.RequestClassEventArgs>:invoke_void_object_TEventArgs (object,SampSharp.GameMode.Events.RequestClassEventArgs)
  at SampSharp.GameMode.BaseMode.OnPlayerRequestClass (SampSharp.GameMode.World.BasePlayer player, SampSharp.GameMode.Events.RequestClassEventArgs e) [0x00000] in <filename unknown>:0
  at SampSharp.GameMode.BaseMode.OnPlayerRequestClass (Int32 playerid, Int32 classid) [0x00000] in <filename unknown>:0 
[part] =AV=Marcel has left the server (0:1)
Tim Potze
@ikkentim
Sep 26 2016 19:44
I’ll be working on it tomorrow evening
Are you on then?
Florian van Dillen
@fvandillen
Sep 26 2016 19:45
Nope.avi, will be out drinking beers :D
But will keep an eye on here the day after
Tim Potze
@ikkentim
Sep 26 2016 19:45
All right, then I’ll just try to find all them bugs and fix em
Florian van Dillen
@fvandillen
Sep 26 2016 19:46
I'll probably find some more while scripting
So i'll keep you busy :D
Oh been wanting to ask, how would I go about doing unit testing for a gamemode and what purpose would it serve?
Tim Potze
@ikkentim
Sep 26 2016 19:49
Have you done some unit testing or UI testing before?
it should be able to do both later
Florian van Dillen
@fvandillen
Sep 26 2016 19:49
Seen some code of others doing it
But not myself
Tim Potze
@ikkentim
Sep 26 2016 19:51
You could basically do UI tests, for example test whether a dialog with a certain title is visible when you type a certain command or press a certain button.
Florian van Dillen
@fvandillen
Sep 26 2016 19:51
And those tests would be performed when, during compile time or runtime?
Tim Potze
@ikkentim
Sep 26 2016 19:51
Or just regular unit tests with thing nearer to s# framework without it crashing
When you run your unit tests. Google for unit tests :)
Florian van Dillen
@fvandillen
Sep 26 2016 19:56
For me, it would be beneficial to verify most of the controller stuff like registering a player, logging in, testing the commands
Tim Potze
@ikkentim
Sep 26 2016 20:06
should all be do-able :)
Florian van Dillen
@fvandillen
Sep 26 2016 20:09
I am working on a basic test to see if it fits my purposes
Tim Potze
@ikkentim
Sep 26 2016 20:09
With SampSharp.Mockery (which still needs a lot of work) should allow you to test much more
Florian van Dillen
@fvandillen
Sep 26 2016 20:09
Can my unit tests make a database connection?
Tim Potze
@ikkentim
Sep 26 2016 20:10
Best practise not to but it could
Florian van Dillen
@fvandillen
Sep 26 2016 20:10
So in my tests I could mock the global group list and just pretend it was loaded from the database?
Tim Potze
@ikkentim
Sep 26 2016 20:11
I’ve never understood exactly how you best test login logic for example :s need to read up on tha one
yea
atm working on the last few touches on the wiki style
Florian van Dillen
@fvandillen
Sep 26 2016 20:12
Hmm it does expose some design flaws in my coding lol
I have a static groups class that has a method called create
And that method puts the test group into the "real" grouplist (IList)
So I must also mock the group creation method which kinda defeats the purpose of testing lol
Tim Potze
@ikkentim
Sep 26 2016 20:15
The idea of unit testing when a database is involved is afaik to have a sort of data provider or repository system where you could switch between data sources
another way would be to have a database filled with expectable test data you never mutate.
Florian van Dillen
@fvandillen
Sep 26 2016 20:16
Hmm sounds about right
Like a second database config in the test project
Using a test database
Tim Potze
@ikkentim
Sep 26 2016 20:16
yes
Florian van Dillen
@fvandillen
Sep 26 2016 20:16
Smart
Note to self: also connect to the database in the test
Florian van Dillen
@fvandillen
Sep 26 2016 20:39
Is there a C# equivalent of var_dump($)?
Like dump a collection/list to the console?
Tim Potze
@ikkentim
Sep 26 2016 20:40
not really, but you can print string.Join(“, “, collection)
Florian van Dillen
@fvandillen
Sep 26 2016 20:41
Doesn't print a whole lot of useful stuff :P
Florian van Dillen
@fvandillen
Sep 26 2016 20:49
I know why :smile:
I am calling Groups.Create( )
Which is in my gamemode
Which tries to use the regular database factory
Somehow I need to make it use my test database class when running the tests
Florian van Dillen
@fvandillen
Sep 26 2016 21:02
Not perfect, but it does work :) http://prntscr.com/cmpkkj
Florian van Dillen
@fvandillen
Sep 26 2016 21:11
Also made a test that registers a player
Thanks for the information man, works like a charm