Java Extension Not Receiving String Packets

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

devlpr
Posts: 4
Joined: 28 Nov 2014, 14:24

Java Extension Not Receiving String Packets

Postby devlpr » 29 Nov 2014, 17:15

This is my first time creating an extension, I tried looking at the docs and everything. I created a simple extension and made it log all requests received. For some reason, it's not receiving the "str" packets. Here's the extension:

Code: Select all

package <redacted>;

import java.nio.channels.SocketChannel;
import java.util.*;

import it.gotoandplay.smartfoxserver.db.*;
import it.gotoandplay.smartfoxserver.data.*;
import it.gotoandplay.smartfoxserver.exceptions.*;
import it.gotoandplay.smartfoxserver.extensions.*;
import it.gotoandplay.smartfoxserver.lib.ActionscriptObject;
import it.gotoandplay.smartfoxserver.events.InternalEventObject;

import org.json.JSONObject;

public class Game extends AbstractExtension
{

   public void init()
   {
      System.out.println("init!");
      trace("Extension initialized");   
   }
   
   @Override
   public void handleRequest(String cmd, String[] data, User u, int fromRoom)
   {
      String[] params = new String[] {
            "testcommand",
            "yes"
       };
            
      LinkedList recipients = new LinkedList();
      recipients.add(u);
      trace ("received str!");
      sendResponse(params, -1, null, recipients);
   }
   
   @Override
   public void handleRequest(String cmd, JSONObject jso, User u, int fromRoom)
   {
      System.out.println("got handlrequest");
      trace ("received a command : " + cmd);
   }
   
   public void handleRequest(String cmd, ActionscriptObject ao, User u, int fromRoom)
   {
      // nothing yet
   }

   @Override
   public void handleInternalEvent(InternalEventObject ieo)
   {
      String event = ieo.getEventName();
      trace ("int event: " + event);
   }
}


Here's the code I'm using to send the XT packet in Flash:

Code: Select all

function sendLogin()
{
   if (!_global.isBusy)
      smartfox.login(zone, login_txt.text, null)
   smartfox.sendXtMessage("test", "loginTest", login_txt.text);
}


I know it's sending because I see the output trace say "[Sending]: %xt%test.."
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Java Extension Not Receiving String Packets

Postby Lapo » 05 Dec 2014, 10:23

You need to specify the protocol in the sendXtMessage call

Example:

Code: Select all

smartfox.sendXtMessage("test", "loginTest", login_txt.text, "str");


the 4th parameter indicates the protocol. If omitted it will default to XML.
Lapo
--
gotoAndPlay()
...addicted to flash games
devlpr
Posts: 4
Joined: 28 Nov 2014, 14:24

Re: Java Extension Not Receiving String Packets

Postby devlpr » 06 Dec 2014, 03:24

Lapo wrote:You need to specify the protocol in the sendXtMessage call

Example:

Code: Select all

smartfox.sendXtMessage("test", "loginTest", login_txt.text, "str");


the 4th parameter indicates the protocol. If omitted it will default to XML.


I must've forgotten that in my original post. But the code I was using before had the proper arguments, so I know it's sending the packet correctly:

Code: Select all

[Sending]: %xt%test%loginTest%-1%undefined%


I know the undefined is an issue but I'm currently just testing XT packets, not really worried about proper data being sent with them. All I receive on the server's side is that it received a login request. No XT packets. Could this be a config issue? This is my current config:

Code: Select all

<SmartFoxConfig>
   
   <ServerSetup>
      <!--
         Specify an ip address or use an asterisk(*) to bind all available IPs
      -->
      <ServerIP>*</ServerIP>
      <ServerPort>9339</ServerPort>
      
      <PolicyAllowedDomains>
         <AllowedDomain>*.mydomain.tld</AllowedDomain>
      </PolicyAllowedDomains>
      
      <AutoSendPolicyFile>true</AutoSendPolicyFile>
      <MaxUserIdleTime>3600</MaxUserIdleTime>
      
      <!-- Server Variables limits (-1 = unlimited) -->
      <MaxRoomVars>-1</MaxRoomVars>
      <MaxUserVars>-1</MaxUserVars>
      
      <!-- New since 1.6.3, optimizes user variables size -->
      <UserVarsOptimization>true</UserVarsOptimization>
      
      <AntiFlood active="false">
         <MinMsgTime tolerance="5">1000</MinMsgTime>
         <MaxRepeatedMessages>3</MaxRepeatedMessages>
         <WarningsBeforeKick>2</WarningsBeforeKick>
         <WarningMessage><![CDATA[No flooding allowed!)]]></WarningMessage>
         <KickMessage><![CDATA[You've been warned! No flooding! Now you're kicked]]></KickMessage>
         <BanMessage><![CDATA[Stop Flooding!! You're being banned]]></BanMessage>         
         <BanAfter timeSpan="1">3</BanAfter>
      </AntiFlood>
      
      <BadWordsFilter active="false">
         <FilterMode>filter</FilterMode> <!-- REMOVE or FILTER -->
         <StripCharacters><![CDATA[,.;:_!$%&/#*-+]]></StripCharacters>
         <Warnings>true</Warnings>
         <FilterRoomNames>true</FilterRoomNames>
         <FilterUserNames>true</FilterUserNames>
         <WarningsBeforeKick>3</WarningsBeforeKick>
         <WarningMessage><![CDATA[No swearing!)]]></WarningMessage>
         <KickMessage><![CDATA[You've been warned! No Swearing! Now you're kicked]]></KickMessage>
         <BanMessage><![CDATA[Stop Swearing! You're being banned!]]></BanMessage>   
         <BanAfter timeSpan="1">3</BanAfter>
         
         <BadWordsList>            
            <badWord>dickhead</badWord>
            <badWord>asshole</badWord>
            <badWord>shithead</badWord>
            <badWord>shit</badWord>
            <badWord>fucking</badWord>
            <badWord>fuck</badWord>
            <badWord>dickhead</badWord>
            <badWord>bastard</badWord>
            <badWord>nigger</badWord>
            <badWord>idiot</badWord>
            <badWord>bitch</badWord>
         </BadWordsList>
      </BadWordsFilter>
      
      <BanCleaning>auto</BanCleaning>
      <BanDuration>1800</BanDuration> <!-- 30 min -->
      <BannedLoginMessage>You have been banned!</BannedLoginMessage>
      
      <OutQueueThreads>2</OutQueueThreads>
      <ExtHandlerThreads>1</ExtHandlerThreads>
      <MaxWriterQueue>50</MaxWriterQueue>

      <ClientMessagQueue>
         <QueueSize>100</QueueSize>
         <MaxAllowedDroppedPackets>10</MaxAllowedDroppedPackets>
      </ClientMessagQueue>
      
      <MaxIncomingQueue>5000</MaxIncomingQueue>
      <DeadChannelsPolicy>strict</DeadChannelsPolicy>
      <MaxMsgLen>4096</MaxMsgLen>
      
      <LogMaxSize>5000000</LogMaxSize>
      <LogMaxFiles>5</LogMaxFiles>
      
      <FileLoggingLevel>INFO</FileLoggingLevel>
      <ConsoleLoggingLevel>INFO</ConsoleLoggingLevel>   
      
      <!-- Adminisitrator login -->
      <AdminLogin>sfs_admin</AdminLogin>
      <AdminPassword>sfs_pass</AdminPassword>
      
      <!-- Allowed administrator IP addresses -->
      <AdminAllowedAddresses>
         <AllowedAddress>*.*.*.*</AllowedAddress>
      </AdminAllowedAddresses>
      
      <!-- Allow remote debugging of extensions -->
      <ExtensionRemoteDebug>true</ExtensionRemoteDebug>
      
      <!--
         Allow global autoreload of extensions upon file save
         You should specify in each Zone if the autoreload is enabled.
      -->
      <AutoReloadExtensions>false</AutoReloadExtensions>
      
      <IpFilter>0</IpFilter>
      
      <Mailer>
         <MailHost>test.mail.com</MailHost>
         <MailUser>foo</MailUser>
         <MailPass>bar</MailPass>
         <SmtpPort>25</SmtpPort>
         <WorkerThreads>1</WorkerThreads>
      </Mailer>
      
      <!-- Enable / Disable remote zone info -->
      <EnableZoneInfo>false</EnableZoneInfo>
      
      <!-- Enable / Disable embedded webserver -->
      <WebServer active="false">
         <CfgFile>webserver/cfg/jetty.xml</CfgFile>
      </WebServer>
      
      <!--  raw custom protocol separator -->
      <RawProtocolSeparator><![CDATA[%]]></RawProtocolSeparator>
      
      <EnableNPC>false</EnableNPC>
      
      <!-- Use concurrent map for properties objects -->
      <DynamicPropertiesClass>java.util.concurrent.ConcurrentHashMap</DynamicPropertiesClass>
      
      <!-- Send a message to client, on wrong Zone. DISABLE THIS ONE IN PRODUCTION
      <WarnOnWrongZoneRequest><![CDATA[Invalid zone: %s]]></WarnOnWrongZoneRequest>
      -->
   </ServerSetup>
   
   
   
   <!--
      Zones Configuration.
   -->
   <Zones>   
   
      <Zone name="cGame" uCountUpdate="false" buddyList="false" maxUsers="1000" customLogin="true">
         <Rooms>
            <Room name="Lobby" maxUsers="1000" isPrivate="false" isTemp="false" uCountUpdate="false" />
         </Rooms>
         
         <Extensions>
            <extension name="test" className="package.location.Class (redacted original)" type="java" />
         </Extensions>
         
         <Moderators status="off">
            <Mod name="Moderator" pwd="moderator" />
         </Moderators>
         
      </Zone>
   
   </Zones>
   
   
</SmartFoxConfig>
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Java Extension Not Receiving String Packets

Postby Lapo » 11 Dec 2014, 12:14

Are you sure you don't have any exceptions on the server side, after sending the request?
Also, are you sure the Extension is actually running?
Adding a trace statement in the init() method will help you make sure your code is working correctly.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
devlpr
Posts: 4
Joined: 28 Nov 2014, 14:24

Re: Java Extension Not Receiving String Packets

Postby devlpr » 12 Dec 2014, 22:12

Lapo wrote:Are you sure you don't have any exceptions on the server side, after sending the request?
Also, are you sure the Extension is actually running?
Adding a trace statement in the init() method will help you make sure your code is working correctly.

cheers



In my first post the init had a trace, so yeah.

There are no exceptions, as far as I know. The handleRequest function just simply traces out a message and sends a packet to the client.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 18 guests