# HG changeset patch # User unc0rr # Date 1211724584 0 # Node ID 8667297755351ecfa6a0797f23b81ff28be1fd4d # Parent 5d49a92c240ad3b2845c70de3e289da0b1afdbd9 Use nick from frontend to prepend chat messages diff -r 5d49a92c240a -r 866729775535 QTfrontend/game.cpp --- 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; } diff -r 5d49a92c240a -r 866729775535 QTfrontend/gameuiconfig.cpp --- 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(); +} diff -r 5d49a92c240a -r 866729775535 QTfrontend/gameuiconfig.h --- 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(); diff -r 5d49a92c240a -r 866729775535 hedgewars/hwengine.dpr --- 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); diff -r 5d49a92c240a -r 866729775535 hedgewars/uChat.pas --- 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; diff -r 5d49a92c240a -r 866729775535 hedgewars/uMisc.pas --- 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}