How to deny the Users at Zonejoin level [Every user is entering into Zone even authentication fails] - smartfoxserver

Recently I am facing a problem that every user (valid/invalid) is joining into the room even I throw the SFSException at ZonejinRequest..
So can anyone explain how to authenticate / stop the invalid users at Zonejoin level with sample snippet. (and also how to remove the joined user from zone if possible)
Thanks in Advance

Hi I got the Bug and it solved,
Here my bug is I put the code like this
try {
if (getApi().checkSecurePassword((ISession)event.getParameter(SFSEventParam.SESSION),plainpwd,pwd)) {
trace("welcome");
} else {
SFSErrorData errData = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
errData.addParameter(username);
throw new SFSLoginException(" Password mismatched ", errData);
}
}
catch(Exception e){}
so My Exception block it self catching that SFSLoginException.. so I removed outer try/catch now working fine.

Related

Can I use this.userId in Meteor.onConnection()?

I am building a mobile application where my users can connect using accounts-facebook.
What I would like to do is refreshing their list of friends that use the app when they are logging in (is this a good way to keep this list up to date ?) or when they are connecting
I built something like this :
Meteor.startup(function(){
myFunctionToRefreshFriendLists()
});
Meteor.onConnection(function(conn) {
if (this.userId) {
myFunctionToRefreshFrindLists();
}
}
But this returns me "undefined", even when the user is connected. I know there is a problem using "this.userId" (this here does not seem relevant to me) but I do not know what to do ?
Any help appreciated, thank you !
Don't use Meteor.onConnection, as it will run every time a user starts a new connection. This can happen frequently depending on the stability of their connection; instead use Accounts.onLogin:
Accounts.onLogin(function(user){
console.log(user.user._id)
});
http://docs.meteor.com/#/full/accounts_onlogin

handle optimistic locking exception grails - mongodb

i need a help for some really serious issue, so the thing is i have a e commerce site , where single user placing order at a time is working fine, but if more than one user try to order the same product, then i am getting this exception
org.grails.datastore.mapping.core.OptimisticLockingException: The instance was updated by another user while you were editing
Point : in.emkart.api.OrderAPIController.save(OrderAPIController.groovy:70)
so my my code is like
/** some code **/
if (product && orderContinue) {
product = updateQuantityForProduct(product)
order?.product = product
/** some code **/
try{
// some code
product.save() // line 70
// some code
}
catch(Exception e){
log.debug "unable to place order-->"+e /** exception --> (unable to place order-->org.grails.datastore.mapping.core.OptimisticLockingException: The instance was updated by another user while you were editing
Point : in.emkart.api.OrderAPIController.save(OrderAPIController.groovy:70) ) **/
}
what are the fixes that can help me to prevent this and also is this possible to keep the another user waiting or some kind of queue to maintain so that once previous order is complete then only next request goes on to place order.

How to wait the p2 profile gets completed

We are using p2 to update our RCP application, and this worked so far quite well until today I realized in some case the P2 IProfile was emty (not null but empty) and always of course return emty result queries.
This happend when launching the application only, meaning that if I request the same profile later in time, I get a complete profile.
The Javadoc of IProfile mention the fact that profile is a snapshot of a particular state.
So it seems I am querying the ProfileRegistry to early and the profile is not yet complete.
I could not find any way on the javadoc to wait for a profile to be filled properly.
I would be grateful to anyone that would help me solve this problem nicely, because using a sleep (which works) is not an acceptable solution.
Thanks.
here is the ugly solution I am implemented, basically testing the time stam to be sure the profile has been loaded
// there seems to be a bug because if the agent is created too quickly then the profile is empty.
// so we loop until we get a proper profile
do {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
interrupted = true;
}
if (agent != null) {
agent.stop();
}
agent = agentProvider.createAgent(getP2AgentUri());
IProfileRegistry profRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
profile = profRegistry.getProfile(getP2ProfileId());
} while (profile != null && profile.getTimestamp() == 0 && !interrupted && !progress.isCanceled());
The profile I use is SELF but I use a method to get the ProfileId because I have JUnit tests that are base on another external p2 profile.

Get Mode in XMPP/Smack

My chat application has a procedure to set the presence/ mode status of the user i.e - Online, Offline, Invisible, Away etc. I am doing this using the following code :-
presence = new Presence(Presence.Type.available);
if (USER_STATE.equalsIgnoreCase("Online")) {
presence.setMode(Presence.Mode.available);
setUserPresence(0);
}else if (USER_STATE.equalsIgnoreCase("Invisible")) {
presence.setMode(Presence.Mode.xa);
setUserPresence(1);
} else if (USER_STATE.equalsIgnoreCase("Away")) {
presence.setMode(Presence.Mode.away);
setUserPresence(2);
} else if (USER_STATE.equalsIgnoreCase("Busy")) {
presence.setMode(Presence.Mode.dnd);
setUserPresence(3);
}
Here when I set the User Presence to Away or Invisible etc. and log out the user. Now when the user is logged in again I want to get the mode of the User that he had set earlier since his last logout. I am getting it as :-
System.out.println("Loggeddd innn");
// Set presence to online!
Presence userPresence = new Presence(Presence.Type.available);
userPresence.setStatus("Hello CCM!");
userPresence.setPriority(24);
userPresence.setMode(userPresence.getMode());
connection.sendPacket(userPresence);
Here I always get NULL in user.getMode() and also I always get Status as Available (shown in openfire portal)
Anybody please help ?
userPresence.setMode(userPresence.getMode()) seems like a no-op to me.
You should store the previous mode on the device itself (eg in SharedPreferences)

WMI and Win32_DeviceChangeEvent - Wrong event type returned?

I am trying to register to a "Device added/ Device removed" event using WMI. When I say device - I mean something in the lines of a Disk-On-Key or any other device that has files on it which I can access...
I am registering to the event, and the event is raised, but the EventType propery is different from the one I am expecting to see.
The documentation (MSDN) states : 1- config change, 2- Device added, 3-Device removed 4- Docking. For some reason I always get a value of 1.
Any ideas ?
Here's sample code :
public class WMIReceiveEvent
{
public WMIReceiveEvent()
{
try
{
WqlEventQuery query = new WqlEventQuery(
"SELECT * FROM Win32_DeviceChangeEvent");
ManagementEventWatcher watcher = new ManagementEventWatcher(query);
Console.WriteLine("Waiting for an event...");
watcher.EventArrived +=
new EventArrivedEventHandler(
HandleEvent);
// Start listening for events
watcher.Start();
// Do something while waiting for events
System.Threading.Thread.Sleep(10000);
// Stop listening for events
watcher.Stop();
return;
}
catch(ManagementException err)
{
MessageBox.Show("An error occurred while trying to receive an event: " + err.Message);
}
}
private void HandleEvent(object sender,
EventArrivedEventArgs e)
{
Console.WriteLine(e.NewEvent.GetPropertyValue["EventType"]);
}
public static void Main()
{
WMIReceiveEvent receiveEvent = new WMIReceiveEvent();
return;
}
}
Well, I couldn't find the code. Tried on my old RAC account, nothing. Nothing in my old backups. Go figure. But I tried to work out how I did it, and I think this is the correct sequence (I based a lot of it on this article):
Get all drive letters and cache
them.
Wait for the WM_DEVICECHANGE
message, and start a timer with a
timeout of 1 second (this is done to
avoid a lot of spurious
WM_DEVICECHANGE messages that start
as start as soon as you insert the
USB key/other device and only end
when the drive is "settled").
Compare the drive letters with the
old cache and detect the new ones.
Get device information for those.
I know there are other methods, but that proved to be the only one that would work consistently in different versions of windows, and we needed that as my client used the ActiveX control on a webpage that uploaded images from any kind of device you inserted (I think they produced some kind of printing kiosk).
Oh! Yup, I've been through that, but using the raw Windows API calls some time ago, while developing an ActiveX control that detected the insertion of any kind of media. I'll try to unearth the code from my backups and see if I can tell you how I solved it. I'll subscribe to the RSS just in case somebody gets there first.
Well,
u can try win32_logical disk class and bind it to the __Instancecreationevent.
You can easily get the required info
I tried this on my system and I eventually get the right code. It just takes a while. I get a dozen or so events, and one of them is the device connect code.