Use nick from frontend to prepend chat messages
authorunc0rr
Sun, 25 May 2008 14:09:44 +0000
changeset 949 866729775535
parent 948 5d49a92c240a
child 950 feb18ec0c5c2
Use nick from frontend to prepend chat messages
QTfrontend/game.cpp
QTfrontend/gameuiconfig.cpp
QTfrontend/gameuiconfig.h
hedgewars/hwengine.dpr
hedgewars/uChat.pas
hedgewars/uMisc.pas
--- a/QTfrontend/game.cpp	Sat May 24 22:28:40 2008 +0000
+++ b/QTfrontend/game.cpp	Sun May 25 14:09:44 2008 +0000
@@ -266,6 +266,7 @@
 	arguments << datadir->absolutePath();
 	arguments << (config->isShowFPSEnabled() ? "1" : "0");
 	arguments << (config->isAltDamageEnabled() ? "1" : "0");
+	arguments << config->netNick().toUtf8().toBase64();
 	return arguments;
 }
 
--- a/QTfrontend/gameuiconfig.cpp	Sat May 24 22:28:40 2008 +0000
+++ b/QTfrontend/gameuiconfig.cpp	Sun May 25 14:09:44 2008 +0000
@@ -78,7 +78,7 @@
 
 	setValue("audio/sound", isSoundEnabled());
 
-	setValue("net/nick", Form->ui.pageOptions->editNetNick->text());
+	setValue("net/nick", netNick());
 	setValue("net/ip", *netHost);
 	setValue("net/port", netPort);
 	setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text());
@@ -134,3 +134,8 @@
 {
 	return depth;
 }
+
+QString GameUIConfig::netNick()
+{
+	return Form->ui.pageOptions->editNetNick->text();
+}
--- a/QTfrontend/gameuiconfig.h	Sat May 24 22:28:40 2008 +0000
+++ b/QTfrontend/gameuiconfig.h	Sun May 25 14:09:44 2008 +0000
@@ -40,6 +40,7 @@
 	bool isAltDamageEnabled();
 	quint8 timerInterval();
 	quint8 bitDepth();
+	QString netNick();
 
 public slots:
 	void SaveOptions();
--- a/hedgewars/hwengine.dpr	Sat May 24 22:28:40 2008 +0000
+++ b/hedgewars/hwengine.dpr	Sun May 25 14:09:44 2008 +0000
@@ -85,6 +85,7 @@
               end;
      gsStart: begin
               InitPlaylistChunk(GetRandom(High(LongWord)));
+              AddClouds;
               AssignHHCoords;
               AddMiscGears;
               StoreLoad;
@@ -184,7 +185,7 @@
 {$ENDIF}
 
 case ParamCount of
-13: begin
+14: begin
      val(ParamStr(2), cScreenWidth);
      val(ParamStr(3), cScreenHeight);
      cBitsStr:= ParamStr(4);
@@ -198,9 +199,9 @@
      PathPrefix:= ParamStr(11);
      cShowFPS:= ParamStr(12) = '1';
      cAltDamage:= ParamStr(13) = '1';
+     UserNick:= DecodeBase64(ParamStr(14));
      for p:= Succ(Low(TPathType)) to High(TPathType) do
-         if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p];
-     AddClouds
+         if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
      end;
   3: begin
      val(ParamStr(2), ipcPort);
--- a/hedgewars/uChat.pas	Sat May 24 22:28:40 2008 +0000
+++ b/hedgewars/uChat.pas	Sun May 25 14:09:44 2008 +0000
@@ -24,6 +24,8 @@
 procedure DrawChat;
 procedure KeyPressChat(Key: Longword);
 
+var UserNick: shortstring = '';
+
 implementation
 uses uMisc, uStore, uConsts, SDLh, uConsole, uKeys;
 
@@ -35,7 +37,6 @@
 		Tex: PTexture;
 		end;
 
-
 var Strs: array[0 .. MaxStrIndex] of TChatLine;
 	lastStr: Longword = 0;
 	visibleCount: Longword = 0;
@@ -110,7 +111,7 @@
 procedure KeyPressChat(Key: Longword);
 const firstByteMark: array[1..4] of byte = (0, $C0, $E0, $F0);
 var i, btw: integer;
-    utf8: shortstring;
+    utf8, s: shortstring;
 begin
 if Key <> 0 then
 	case Key of
@@ -122,8 +123,9 @@
 		13, 271: begin
 			if Length(InputStr.s) > 0 then
 				begin
-				AddChatString(InputStr.s);
-				ParseCommand('/say ' + InputStr.s, true);
+				s:= UserNick + ': ' + InputStr.s;
+				AddChatString(s);
+				ParseCommand('/say ' + s, true);
 				SetLine(InputStr, '')
 				end;
 			FreezeEnterKey;
--- a/hedgewars/uMisc.pas	Sat May 24 22:28:40 2008 +0000
+++ b/hedgewars/uMisc.pas	Sun May 25 14:09:44 2008 +0000
@@ -118,6 +118,7 @@
 function  Surface2Tex(surf: PSDL_Surface): PTexture;
 procedure FreeTexture(tex: PTexture);
 function  toPowerOf2(i: Longword): Longword;
+function DecodeBase64(s: shortstring): shortstring;
 
 var CursorPoint: TPoint;
     TargetPoint: TPoint = (X: NoPointX; Y: 0);
@@ -247,18 +248,6 @@
 Str2PChar:= @CharArray
 end;
 
-{$IFDEF DEBUGFILE}
-procedure AddFileLog(s: shortstring);
-begin
-writeln(f, GameTicks: 6, ': ', s);
-flush(f)
-end;
-
-function RectToStr(Rect: TSDL_Rect): shortstring;
-begin
-RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
-end;
-
 function isPowerOf2(i: Longword): boolean;
 begin
 if i = 0 then exit(true);
@@ -326,6 +315,46 @@
 dispose(tex)
 end;
 
+function DecodeBase64(s: shortstring): shortstring;
+const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
+var i, t, c: Longword;
+begin
+c:= 0;
+for i:= 1 to Length(s) do
+	begin
+	t:= Pos(s[i], table);
+	if s[i] = '=' then inc(c);
+	if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0
+	end;
+
+i:= 1;
+t:= 1;
+while i <= length(s) do
+	begin
+	DecodeBase64[t    ]:= char((byte(s[i    ]) shl 2) or (byte(s[i + 1]) shr 4));
+	DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2));
+	DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3])      ));
+	inc(t, 3);
+	inc(i, 4)
+	end;
+
+if c < 3 then t:= t - c;
+
+byte(DecodeBase64[0]):= t - 1
+end;
+
+{$IFDEF DEBUGFILE}
+procedure AddFileLog(s: shortstring);
+begin
+writeln(f, GameTicks: 6, ': ', s);
+flush(f)
+end;
+
+function RectToStr(Rect: TSDL_Rect): shortstring;
+begin
+RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
+end;
+
 var i: LongInt;
 {$ENDIF}