clientLogin rebuilded
I applied a facade pattern on method clientLogin and
add a new method for check if user has already logged.
Send the entire MMServer.java file so find the string
BLACKRAIDER for a starting point of my mods.
Hope this helps.
Thank you for your submission. I do have a question though:
Is there a reason the methods you added (like isNobody) do
not take paramters but use a global variable (username)
instead? I suppose it could be problematic once multiple
users sign on at a similar time as the clientLogin method is
not synchronized and might as well be called by multiple
client-threads at once..(thus overwriting username)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First of all thanks for take time to read the mod.
As far as I know clientLogin is an instance method.
This means that every client must have his own instance of
MMServ class before calling any non-static method on the
class (included clientLogin, and inherently the username field).
I suposse you use a RPC mechanism for have an unique
instance of the server and retrieve the instance of the
server to the client-threads. The approach you've take don't
protect you in the issue you related. The fact is simple:
two clients accessing to the same piece of code at the same
time (whitout protection) can result in an unpredictable
behavior of the code.
Imagine two clients that access the server at same time and
both using the same parameters (username and pwd). Both
reach the clientLogin function as pass it clearly for the
reason that the method don't have enough time to refresh the
data. Both users are registered and probably one of them
raises an exception when the method try to add one to users
collection.
By this way you could sinchronize the method through
username field and assure that two or more clients don't log
in at the same time.
Another reason for split the method in a few pieces of code
is readability. This way improve the readability of the
entire login process, with the added advantage that could
add new special account types or new checks whitout break
this concept.
I send you the file with the correct sintax checking and
with the method synchronized.
Hope this helps.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'll be a bit busy over the next days, but I promise to look
at it closer once I get some free time. Just to keep you
informed, that I didn't forget you :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=168906
Thank you for your submission. I do have a question though:
Is there a reason the methods you added (like isNobody) do
not take paramters but use a global variable (username)
instead? I suppose it could be problematic once multiple
users sign on at a similar time as the clientLogin method is
not synchronized and might as well be called by multiple
client-threads at once..(thus overwriting username)
Logged In: YES
user_id=1248031
First of all thanks for take time to read the mod.
As far as I know clientLogin is an instance method.
This means that every client must have his own instance of
MMServ class before calling any non-static method on the
class (included clientLogin, and inherently the username field).
I suposse you use a RPC mechanism for have an unique
instance of the server and retrieve the instance of the
server to the client-threads. The approach you've take don't
protect you in the issue you related. The fact is simple:
two clients accessing to the same piece of code at the same
time (whitout protection) can result in an unpredictable
behavior of the code.
Imagine two clients that access the server at same time and
both using the same parameters (username and pwd). Both
reach the clientLogin function as pass it clearly for the
reason that the method don't have enough time to refresh the
data. Both users are registered and probably one of them
raises an exception when the method try to add one to users
collection.
By this way you could sinchronize the method through
username field and assure that two or more clients don't log
in at the same time.
Another reason for split the method in a few pieces of code
is readability. This way improve the readability of the
entire login process, with the added advantage that could
add new special account types or new checks whitout break
this concept.
I send you the file with the correct sintax checking and
with the method synchronized.
Hope this helps.
Logged In: YES
user_id=168906
I'll be a bit busy over the next days, but I promise to look
at it closer once I get some free time. Just to keep you
informed, that I didn't forget you :)