Hello, I've been trying to play a bit in a chatbox in an online game that I play often, it's all flash and I have decompiled it to look into the sourcecode, but I'm not really finding what I'm looking for or try to do...
I've succeeded in other tricks, quite a lot in fact already on that site
But what I'd love to be able to do is change things in this flash based chatbox, like the color of what you write, the name with whom you post your message... etc. I'm sure there are ways but I failed up til now, I'm not too expierenced with actionscript code and therefore I thought maybe someone else would see more in this code for what I am trying to do.... Cuz I was tipped to read the code to find what I need, but I can't find it.
package
{
import fl.controls.*;
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
import it.gotoandplay.smartfoxserver.util.*;
public class Chat extends Object
{
private var mChatBuffer:String;
private var mScrollMarqueeCB:Function;
private var mFilterSpectators:Boolean;
private var mFocusCB:Function;
private var mIsFriendCB:Function;
private var mIsPlayerCB:Function;
private var mFocusTimer:Timer;
private var mIsBlockedCB:Function;
private var mLinkCB:Function;
private var mFilterPlayers:Boolean;
private var mChatWindow:MovieClip;
private var mFilterGameMessages:Boolean;
private var mFilterRoomNotices:Boolean;
private var mIsMouseToFocus:Boolean;
private var mFilterBlockedUsers:Boolean;
private var mBeforeMessagePosition:int;
private var mNet:LiveNet;
private var mInputCB:Function;
private static const kFontColors:Array = [16711680, 30464, 11154431, 255, 0, 11615759, 16742178, 26487, 11206913, 65963];
public function Chat(param1:MovieClip, param2:LiveNet)
{
this.mIsMouseToFocus = false;
this.mFocusTimer = new Timer(200);
this.mFocusTimer.addEventListener(TimerEvent.TIMER, this.OnFocusTime);
this.SetAsset(param1, true);
this.mNet = param2;
this.mNet.SetPublicMessageCB(this.OnMessage);
this.mNet.SetChatBufferCB(this.SetChatBuffer);
return;
}// end function
private function OnFocusEvent(event:FocusEvent) : void
{
if (event.type == FocusEvent.FOCUS_IN)
{
this.mChatWindow.stage.focus = this.mChatWindow.chatInput_txt;
if (this.mFocusCB != null)
{
this.mFocusCB(event);
}
}
return;
}// end function
private function OnMessage(param1:int, param2:String, param3:String, param4:Boolean = false) : void
{
var _loc_5:* = null;
var _loc_6:* = null;
var _loc_7:* = 0;
var _loc_8:* = null;
var _loc_9:* = null;
var _loc_11:* = 0;
var _loc_12:* = null;
var _loc_13:* = 0;
var _loc_14:* = 0;
var _loc_15:* = null;
var _loc_16:* = null;
_loc_5 = new TextFormat();
_loc_5.url = "";
_loc_5.underline = false;
_loc_6 = new TextFormat();
_loc_6.url = "";
_loc_6.underline = false;
if (param1 == NetBase.kDevToUserMessageId)
{
_loc_5.color = kFontColors[3];
_loc_5.underline = true;
_loc_6.color = kFontColors[4];
_loc_6.underline = false;
}
else if (param1 == NetBase.kSystemMessageId)
{
_loc_5.color = kFontColors[1];
_loc_6.color = kFontColors[1];
if (this.mFilterRoomNotices && (param3.indexOf("entered") != -1 || param3.indexOf("left") != -1))
{
return;
}
if (this.mFilterGameMessages && param3.indexOf("KO\'d") != -1)
{
return;
}
}
else if (param1 == NetBase.kSupportMessageId)
{
_loc_5.color = kFontColors[5];
_loc_6.color = kFontColors[6];
}
else if (param1 == NetBase.kCriticalSupportMessageId)
{
_loc_5.color = kFontColors[5];
_loc_6.color = kFontColors[0];
}
else
{
if (this.mFilterSpectators && this.mIsPlayerCB != null && !this.mIsPlayerCB(param1))
{
return;
}
if (this.mFilterPlayers && (this.mIsPlayerCB == null || this.mIsPlayerCB(param1)))
{
return;
}
_loc_7 = param3.indexOf("_");
if (_loc_7 != -1)
{
_loc_9 = param3;
_loc_8 = _loc_9.slice(0, _loc_7);
param3 = _loc_9.slice((_loc_7 + 1), _loc_9.length);
}
if (_loc_8 != null && this.mFilterBlockedUsers && this.mIsBlockedCB != null && this.mIsBlockedCB(_loc_8))
{
return;
}
if (param2 == this.mNet.GetUserName())
{
_loc_5.color = kFontColors[2];
_loc_6.color = kFontColors[4];
}
else
{
_loc_5.color = kFontColors[3];
_loc_5.underline = false;
if (this.mIsFriendCB(_loc_8))
{
_loc_6.color = kFontColors[7];
_loc_6.underline = false;
}
else
{
_loc_6.color = kFontColors[4];
_loc_6.underline = false;
}
}
if (this.mNet.GetGame().GetLiveScript())
{
_loc_11 = this.mNet.GetGame().GetLiveScript().GetTeamIdByNetId(param1);
if (_loc_11 == 0)
{
_loc_5.color = kFontColors[9];
_loc_6.color = kFontColors[9];
_loc_6.underline = false;
}
else if (_loc_11 == 1)
{
_loc_5.color = kFontColors[8];
_loc_6.color = kFontColors[8];
_loc_6.underline = false;
}
}
}
if (this.mChatWindow.name != "chatInGame_mc" && param2 == "Tetris Support")
{
this.mScrollMarqueeCB(param3, param4);
return;
}
if (param2 == this.mNet.GetUserName() || Math.max(1, this.mChatWindow.chat_txt.numLines - 17) == this.mChatWindow.chat_txt.scrollV)
{
this.mBeforeMessagePosition = -1;
}
else
{
this.mBeforeMessagePosition = this.mChatWindow.chat_txt.scrollV;
}
if (_loc_5.underline)
{
this.mChatWindow.chat_txt.htmlText = this.mChatWindow.chat_txt.htmlText + ("<a href=\'event:" + param2 + "\'>" + param2 + "</a>");
}
else
{
this.mChatWindow.chat_txt.appendText(param2);
this.mChatWindow.chat_txt.setTextFormat(_loc_5, this.mChatWindow.chat_txt.text.length - param2.length - 1, this.mChatWindow.chat_txt.length);
}
this.mChatWindow.chat_txt.selectable = false;
var _loc_10:* = _loc_9.indexOf("<a href");
if (_loc_5.underline || (_loc_10 == -1 || param1 != NetBase.kSupportMessageId && param1 != NetBase.kCriticalSupportMessageId))
{
this.mChatWindow.chat_txt.appendText(": " + param3 + "\n");
this.mChatWindow.chat_txt.setTextFormat(_loc_6, this.mChatWindow.chat_txt.text.length - _loc_9.length - 1, this.mChatWindow.chat_txt.length);
}
else
{
this.mChatWindow.chat_txt.appendText(": ");
_loc_12 = _loc_9.substr(0, _loc_10);
_loc_13 = _loc_9.indexOf("</a>", _loc_10);
_loc_14 = this.mChatWindow.chat_txt.length;
if (_loc_13 != -1)
{
_loc_13 = _loc_13 + 4;
_loc_15 = _loc_9.substr(_loc_13, _loc_9.length - _loc_13);
if (_loc_12 != "")
{
this.mChatWindow.chat_txt.appendText(_loc_12);
this.mChatWindow.chat_txt.setTextFormat(_loc_6, _loc_14, _loc_14 + _loc_10);
}
_loc_16 = _loc_9.substr(_loc_10, _loc_13 - _loc_10);
_loc_13 = this.mChatWindow.chat_txt.length;
if (_loc_16 != "")
{
this.mChatWindow.chat_txt.htmlText = this.mChatWindow.chat_txt.htmlText + _loc_16;
}
if (_loc_15 != "")
{
_loc_13 = this.mChatWindow.chat_txt.length;
this.mChatWindow.chat_txt.appendText(_loc_15);
this.mChatWindow.chat_txt.setTextFormat(_loc_6, _loc_13, this.mChatWindow.chat_txt.length);
}
this.mChatWindow.chat_txt.appendText("\n");
}
}
this.UpdateScroll();
return;
}// end function
public function IsFilterRoomNotices() : Boolean
{
return this.mFilterRoomNotices;
}// end function
private function OnFocusTime(event:TimerEvent) : void
{
this.mFocusTimer.stop();
this.mChatWindow.stage.focus = this.mChatWindow.chatInput_txt;
return;
}// end function
public function SetInputCB(param1:Function) : void
{
this.mInputCB = param1;
return;
}// end function
public function SetScrollMarqueeCB(param1:Function) : void
{
this.mScrollMarqueeCB = param1;
return;
}// end function
public function SetFocusCB(param1:Function) : void
{
this.mFocusCB = param1;
return;
}// end function
public function WriteChatToCookie() : void
{
var cookie:SharedObject;
var str:String;
cookie = SharedObject.getLocal("ChatToReport", "/");
if (cookie)
{
try
{
str = this.mChatWindow.chat_txt.text;
cookie.clear();
cookie.data.chat = encodeURIComponent(str.substring(str.length - 10000 >= 0 ? (0) : (str.length - 10000), str.length));
cookie.flush();
}
catch (error:Error)
{
trace("Cookie Write Error : Error while writing data variables");
}
}
return;
}// end function
public function SetIsBlockedCB(param1:Function) : void
{
this.mIsBlockedCB = param1;
return;
}// end function
public function SetChatBuffer(param1:String) : void
{
this.mChatBuffer = null;
this.mChatBuffer = param1;
this.Clear();
return;
}// end function
private function UpdateScroll() : void
{
if (this.mChatWindow.chat_txt.textHeight > UIScrollBar(this.mChatWindow.chat_sb).height)
{
this.mChatWindow.chat_sb.visible = true;
this.mChatWindow.chat_sb.update();
}
else
{
this.mChatWindow.chat_sb.visible = false;
}
if (this.mBeforeMessagePosition == -1)
{
this.mChatWindow.chat_txt.scrollV = Math.max(0, this.mChatWindow.chat_txt.numLines - 12);
}
else
{
this.mChatWindow.chat_txt.scrollV = this.mBeforeMessagePosition;
}
return;
}// end function
public function SetIsFriendCB(param1:Function) : void
{
this.mIsFriendCB = param1;
return;
}// end function
public function SetIsPlayerCB(param1:Function) : void
{
this.mIsPlayerCB = param1;
return;
}// end function
public function Clear() : void
{
var _loc_1:* = null;
var _loc_2:* = 0;
var _loc_3:* = null;
var _loc_4:* = null;
var _loc_5:* = null;
if (this.mChatWindow)
{
this.mChatWindow.chat_txt.text = "";
this.mChatWindow.chatInput_txt.text = "";
this.mChatWindow.chatInput_txt.setSelection(0, 0);
this.UpdateScroll();
if (this.mChatBuffer != null && this.mChatBuffer.length > 0)
{
_loc_1 = this.mChatBuffer.slice(0, (this.mChatBuffer.length - 1)).split("|");
_loc_2 = 0;
for each (_loc_3 in _loc_1)
{
_loc_4 = _loc_3.split("~");
_loc_5 = _loc_4[0];
if (_loc_5.indexOf("TetrisSupport") != -1 || _loc_5.indexOf("Tetris Support") != -1)
{
if (_loc_5.charAt(0) == 1)
{
_loc_2 = NetBase.kCriticalSupportMessageId;
}
else
{
_loc_2 = NetBase.kSupportMessageId;
}
_loc_5 = "Tetris Support";
}
else
{
_loc_2 = 0;
}
this.OnMessage(_loc_2, _loc_5, Entities.decodeEntities(String(_loc_4[1]).replace("&", "&")));
}
}
}
return;
}// end function
private function OnMouseDown(event:MouseEvent) : void
{
this.mFocusTimer.reset();
this.mFocusTimer.start();
this.mIsMouseToFocus = true;
return;
}// end function
public function WriteFilters() : void
{
var so:SharedObject;
so = SharedObject.getLocal(this.mNet.GetUserName() + "chatfilters");
try
{
so.data.block = this.mFilterBlockedUsers;
so.data.gm = this.mFilterGameMessages;
so.data.player = this.mFilterPlayers;
so.data.rn = this.mFilterRoomNotices;
so.data.spec = this.mFilterSpectators;
so.flush();
}
catch (e:Error)
{
}
return;
}// end function
public function SendMessage(param1:String) : void
{
var _loc_2:* = null;
var _loc_3:* = 0;
var _loc_6:* = false;
var _loc_7:* = false;
var _loc_8:* = false;
var _loc_9:* = null;
var _loc_4:* = /~/g;
var _loc_5:* = /\|/g;
param1 = param1.replace(_loc_4, "").replace(_loc_5, "");
if (param1.charAt(0) == "!" && OWUser.GetUser().GetIsDeveloper())
{
_loc_2 = param1;
_loc_6 = false;
_loc_7 = false;
_loc_8 = false;
_loc_3 = _loc_2.indexOf("!!");
if (_loc_3 == 0)
{
_loc_2 = _loc_2.slice(2, _loc_2.length);
_loc_6 = true;
}
else
{
_loc_2 = _loc_2.slice(1, _loc_2.length);
}
if (_loc_2.charAt(0) == "*")
{
_loc_7 = true;
_loc_2 = _loc_2.slice(1, _loc_2.length);
}
this.mNet.SendModeratorMessage(_loc_2 + "\n", _loc_6, _loc_7, _loc_8);
}
else if (param1.charAt(0) == "[" && param1.charAt(1) != "]" && OWUser.GetUser().GetIsDeveloper())
{
_loc_2 = param1;
_loc_3 = _loc_2.indexOf("]");
if (_loc_3 != -1)
{
_loc_9 = _loc_2.slice(1, _loc_3);
_loc_2 = _loc_2.slice((_loc_3 + 1), _loc_2.length);
this.mNet.SendModeratorMessage(_loc_2 + "\n", false, false, _loc_8, _loc_9);
}
}
else
{
this.mNet.SendPublicChat(param1);
}
return;
}// end function
public function SetAsset(param1:MovieClip, param2:Boolean = false) : void
{
if (param1)
{
this.mChatWindow = param1;
this.mChatWindow.chat_txt.addEventListener(TextEvent.LINK, this.OnTextLink);
this.mChatWindow.chatInput_txt.maxChars = OWUser.GetUser().GetIsDeveloper() ? (null) : (120);
this.mChatWindow.chatInput_txt.text = "";
if (!OWUser.GetUser().GetIsEmailVerified())
{
this.mChatWindow.chatInput_txt.type = TextFieldType.DYNAMIC;
}
this.mChatWindow.chatInput_txt.addEventListener(TextEvent.TEXT_INPUT, this.OnTextInput);
this.mChatWindow.chatInput_txt.restrict = " -~";
this.mChatWindow.addEventListener(FocusEvent.FOCUS_IN, this.OnFocusEvent, false, 0, true);
this.mChatWindow.addEventListener(MouseEvent.MOUSE_DOWN, this.OnMouseDown, false, 0, true);
if (param2)
{
this.Clear();
}
if (param2)
{
this.mFilterBlockedUsers = false;
this.mFilterGameMessages = false;
this.mFilterPlayers = false;
this.mFilterRoomNotices = false;
this.mFilterSpectators = false;
this.mIsBlockedCB = null;
this.mIsPlayerCB = null;
this.mLinkCB = null;
this.mIsFriendCB = null;
this.mFocusTimer.stop();
}
}
else
{
this.mFocusTimer.stop();
this.mChatWindow.chat_txt.removeEventListener(TextEvent.LINK, this.OnTextLink);
this.mChatWindow.removeEventListener(FocusEvent.FOCUS_IN, this.OnFocusEvent);
this.mChatWindow.chat_txt.removeEventListener(MouseEvent.MOUSE_DOWN, this.OnMouseDown);
this.mChatWindow.chatInput_txt.removeEventListener(TextEvent.TEXT_INPUT, this.OnTextInput);
this.mChatWindow = null;
}
return;
}// end function
public function SetLinkCB(param1:Function) : void
{
this.mLinkCB = param1;
return;
}// end function
public function GetIsMouseToFocus() : Boolean
{
return this.mIsMouseToFocus;
}// end function
public function SetFilters(param1:Boolean, param2:Boolean, param3:Boolean, param4:Boolean, param5:Boolean) : void
{
this.mFilterRoomNotices = param1;
this.mFilterGameMessages = param2;
this.mFilterBlockedUsers = param3;
this.mFilterPlayers = param5;
this.mFilterSpectators = param4;
this.WriteFilters();
return;
}// end function
public function Fini() : void
{
if (this.mFocusTimer)
{
this.mFocusTimer.stop();
this.mFocusTimer.removeEventListener(TimerEvent.TIMER, this.OnFocusTime);
this.mFocusTimer = null;
}
this.mChatWindow.removeEventListener(FocusEvent.FOCUS_IN, this.OnFocusEvent);
this.mChatWindow.chat_txt.removeEventListener(MouseEvent.MOUSE_DOWN, this.OnMouseDown);
this.mChatWindow.chatInput_txt.removeEventListener(TextEvent.TEXT_INPUT, this.OnTextInput);
this.mChatWindow = null;
this.mNet = null;
this.mFocusCB = null;
return;
}// end function
public function ReadFilters() : void
{
var _loc_1:* = null;
_loc_1 = SharedObject.getLocal(this.mNet.GetUserName() + "chatfilters");
if (_loc_1 && _loc_1.data && _loc_1.data.block)
{
this.mFilterBlockedUsers = _loc_1.data.block;
this.mFilterGameMessages = _loc_1.data.gm;
this.mFilterPlayers = _loc_1.data.player;
this.mFilterRoomNotices = _loc_1.data.rn;
this.mFilterSpectators = _loc_1.data.spec;
}
else
{
this.mFilterBlockedUsers = true;
this.mFilterGameMessages = false;
this.mFilterPlayers = false;
this.mFilterRoomNotices = false;
this.mFilterSpectators = false;
}
return;
}// end function
public function IsFilterSpectators() : Boolean
{
return this.mFilterSpectators;
}// end function
public function IsFilterGameMessages() : Boolean
{
return this.mFilterGameMessages;
}// end function
public function GetAsset() : MovieClip
{
return this.mChatWindow;
}// end function
public function SetIsMouseToFocus(param1:Boolean) : void
{
this.mIsMouseToFocus = param1;
return;
}// end function
private function OnTextInput(event:TextEvent) : void
{
var _loc_2:* = false;
var _loc_3:* = 0;
if (event.text == "\n")
{
event.preventDefault();
if (this.mChatWindow.chatInput_txt.text != "")
{
_loc_2 = false;
_loc_3 = 0;
while (_loc_3 < this.mChatWindow.chatInput_txt.text.length)
{
if (this.mChatWindow.chatInput_txt.text.charAt(_loc_3) != " ")
{
_loc_2 = true;
break;
}
_loc_3++;
}
if (_loc_2)
{
this.SendMessage(this.mChatWindow.chatInput_txt.text);
}
this.mChatWindow.chatInput_txt.text = "";
this.mChatWindow.chatInput_txt.setSelection(0, 0);
}
if (this.mInputCB != null)
{
this.mInputCB();
}
}
return;
}// end function
public function OnTextLink(event:TextEvent) : void
{
if (this.mLinkCB != null)
{
this.mLinkCB(event);
}
return;
}// end function
public function IsFilterPlayers() : Boolean
{
return this.mFilterPlayers;
}// end function
public function GetInputTextField() : TextField
{
return this.mChatWindow.chatInput_txt;
}// end function
public function IsFilterBlockedUsers() : Boolean
{
return this.mFilterBlockedUsers;
}// end function
}
}
I think this part of code is the most important in this... though there is more code but this looks the most interesting...
Any help would be greatly appreciated!
So the thing I would like to do the most with this is change the name which im posting messages with