Cyrillic utfString problems

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

croftie
Posts: 39
Joined: 24 Jul 2013, 08:35
Location: Algarve Portugal
Contact:

Cyrillic utfString problems

Postby croftie » 13 Oct 2020, 17:04

Sending cyrillic text string by putting a utfString into an ISFSObject causes a server error on receipt at the server end. It works fine with latin (english) text and it works find sending the same cyrillic message from server to client. But when the message is sent client to server the following trace appears.
16:43:23,523 WARN [SFSWorker:Sys:1] jetty.WebSocketBinaryProtocolCodec - java.lang.IllegalStateException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.IllegalStateException
Message: Invalid SFSObject key length. Found = -12112
Description: Serialization error in incoming websocket packet.
From: { Id: 1, Type: WEBSOCKET, Logged: Yes, IP: 84.9.169.108:63817 }
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.decodeSFSObject(DefaultSFSDataSerializer.java:205)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.decodeObject(DefaultSFSDataSerializer.java:743)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.decodeSFSObject(DefaultSFSDataSerializer.java:212)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.decodeObject(DefaultSFSDataSerializer.java:743)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.decodeSFSObject(DefaultSFSDataSerializer.java:212)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.binary2object(DefaultSFSDataSerializer.java:170)
com.smartfoxserver.v2.entities.data.SFSObject.newFromBinaryData(SFSObject.java:149)
com.smartfoxserver.bitswarm.websocket.jetty.WebSocketBinaryProtocolCodec.onPacketRead(WebSocketBinaryProtocolCodec.java:58)
sfs2x.websocket.SFS2XWSService$WSIOExecutor.run(SFS2XWSService.java:102)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Any Ideas?
User avatar
Lapo
Site Admin
Posts: 21678
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cyrillic utfString problems

Postby Lapo » 14 Oct 2020, 06:54

Hi,
please show me the code that causes the problem.
Also specify which version of SFS2X you're using and which client API language and version, too.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
croftie
Posts: 39
Joined: 24 Jul 2013, 08:35
Location: Algarve Portugal
Contact:

Re: Cyrillic utfString problems

Postby croftie » 14 Oct 2020, 08:39

We are using
SmartFoxServer 2X (2.13.0)
Javascript api 1.7.4


Code: Select all

sendMessage: function () {
        if ($("#chatTextInput").val().length > 0) {
            controlPanel.buttonSound.play();
            var sParams = new SFS2X.SFSObject();
            sParams.putUtfString("playerFunction", "chat");
            sParams.putUtfString("message", $("#chatTextInput").val());
            sParams.putUtfString("type", "text");
            sfs.send(new SFS2X.ExtensionRequest("playerRequest", sParams));
            $("#chatTextInput").val("");
            console.log(sParams.getDump());
        }
    },


The console log produces

(utf_string) playerFunction: chat
(utf_string) message: Привет, как дела
(utf_string) type: text


The server code (truncated)

Code: Select all

public void handleClientRequest(User user, ISFSObject sfso) {
      SFSExtension ext = getParentExtension();
      String playerFunction = sfso.getUtfString("playerFunction");
      switch (playerFunction) {
      //other cases
      case "chat":
         ChatRequest chr=new ChatRequest(ext);
         chr.request(user, sfso);
         break;
      //other cases
      default:
         trace("no player function " + playerFunction);
         break;

      }

   }

The chatrequest class is below but the trace messages at the top are never reached

Code: Select all

package com.package;

import java.util.ArrayList;

import com.simoncroft.livecasinohosts.databaseFunctions.DBInsert;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSArray;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class ChatRequest {
   SFSExtension ext;

   public ChatRequest(SFSExtension extension) {
      ext = extension;
   }
   
   public void request(User user, ISFSObject sfso) {
      ext.trace("chat request");
      ext.trace(sfso.getDump());
      
      int localUserid = (int) user.getSession().getProperty("localUserid");
      Room room = user.getLastJoinedRoom();
      String messageType = sfso.getUtfString("type");
      ArrayList<User> recipients = new ArrayList<User>();
      ISFSObject msg = new SFSObject();
      msg.putUtfString("sender", user.getName());
      int transid = -1;
      String sql = "";

      Object dbObject = new Object[] {};

      switch (messageType) {
      case "text":
         msg.putUtfString("type", "text");
         for (User resident : room.getUserList()) {
            int userType = (int) resident.getSession().getProperty("userType");
            switch (userType) {
            case 1:
               if (!user.containsVariable("mute")) {
                  recipients.add(resident);
               }
               break;
            case 2:
               if (!user.containsVariable("mute")) {
                  recipients.add(resident);
               }
               break;
            case 3:
               recipients.add(resident);
               break;
            }
         }
         msg.putUtfString("message", sfso.getUtfString("message"));
         sql = "insert into chat (localUserid, tablename, username, message) values (?,?,?,?)";
         dbObject = new Object[] { localUserid, room.getName(), user.getName(), sfso.getUtfString("message") };
         break;
      case "phrase":
         msg.putUtfString("type", "text");
         recipients = (ArrayList<User>) room.getUserList();
         int phrase_id = Integer.parseInt(sfso.getUtfString("phrase"));
         ISFSArray chatPhrases = room.getVariable("chatPhrases").getSFSArrayValue();
         ISFSObject phraseObj = chatPhrases.getSFSObject(phrase_id);

         msg.putUtfString("message", phraseObj.getUtfString("phrase"));
         sql = "insert into chat (localUserid, tablename, username, message) values (?,?,?,?)";
         dbObject = new Object[] { localUserid, room.getName(), user.getName(), phraseObj.getUtfString("phrase") };

         break;
      case "emoticon":
         msg.putUtfString("type", "emoticon");
         recipients = (ArrayList<User>) room.getUserList();
         msg.putUtfString("emoticon", sfso.getUtfString("emoticon"));
         sql = "insert into chat (localUserid, tablename, username, emoticon) values (?,?,?,?)";
         dbObject = new Object[] { localUserid, room.getName(), user.getName(), sfso.getUtfString("emoticon") };
         break;
      case "private":
         recipients.add(user);
         User recipient = room.getUserByName(sfso.getUtfString("recipient"));
         recipients.add(recipient);
         msg.putUtfString("type", "private");
         msg.putUtfString("message", sfso.getUtfString("message"));
         sql = "insert into chat (localUserid, tablename, username, message) values (?,?,?,?)";
         dbObject = new Object[] { localUserid, room.getName(), user.getName(), sfso.getUtfString("message") };
         break;
      }

      ext.send("chat", msg, recipients);

      DBInsert dbi = new DBInsert(ext);
      transid = dbi.InsertWithID(sql, dbObject, "send chat");
      sql = "insert into chat_recipients (message_id, localUserid, username) values (?,?,?)";
      for (User recipient : recipients) {
         if (user != recipient && !recipient.isNpc()) {
            int rlocalUserid = (int) recipient.getSession().getProperty("localUserid");
            dbObject = new Object[] { transid, rlocalUserid, recipient.getName() };
            dbi.Insert(sql, dbObject, "send chat");
         }
      }
   }
}
User avatar
Lapo
Site Admin
Posts: 21678
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cyrillic utfString problems

Postby Lapo » 14 Oct 2020, 09:59

Hi,
I would recommend an update. The server and client API are pretty old, the client API in particular. The server has never had issues with UTF characters, and cyrillic (as well as many other non-latin char sets) have been used by many customers.

It's possible that it is a client API issue, but unfortunately those API are over 10 releases old (Latest JS release is 1.7.17).

Please make sure to upgrade and let us know.
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
croftie
Posts: 39
Joined: 24 Jul 2013, 08:35
Location: Algarve Portugal
Contact:

Re: Cyrillic utfString problems

Postby croftie » 14 Oct 2020, 12:11

client api update to 1.7.17 did the trick

Thank you

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 2 guests