99using Terraria ;
1010using Terraria . ModLoader ;
1111using Terraria . ID ;
12+ using Terraria . Localization ;
1213
1314namespace HEROsMod . HEROsModNetwork
1415{
@@ -174,7 +175,7 @@ public static void Update()
174175 if ( sendTimeTimer <= 0 )
175176 {
176177 sendTimeTimer = 1f ;
177- NetMessage . SendData ( 7 , - 1 , - 1 , "" , 0 , 0f , 0f , 0f , 0 ) ;
178+ NetMessage . SendData ( 7 , - 1 , - 1 , null , 0 , 0f , 0f , 0f , 0 ) ;
178179 }
179180 }
180181 }
@@ -340,7 +341,7 @@ public static bool CheckIncomingDataForHEROsModMessage(ref byte msgType, ref Bin
340341 {
341342 LastTileKilledBy = player ;
342343 WorldGen . KillTile ( x , y , fail , false , false ) ;
343- NetMessage . SendData ( 17 , - 1 , playerNumber , "" , ( int ) tileModifyType , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
344+ NetMessage . SendData ( 17 , - 1 , playerNumber , null , ( int ) tileModifyType , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
344345 LastTileKilledBy = null ;
345346 return true ;
346347 }
@@ -358,55 +359,55 @@ public static bool CheckIncomingDataForHEROsModMessage(ref byte msgType, ref Bin
358359 switch ( tileModifyType )
359360 {
360361 case TileModifyType . KillTile :
361- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . PlaceTile , ( float ) x , ( float ) y , ( float ) tile . type , tile . slope ( ) ) ;
362+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . PlaceTile , ( float ) x , ( float ) y , ( float ) tile . type , tile . slope ( ) ) ;
362363 break ;
363364 case TileModifyType . PlaceTile :
364- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . KillTile , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
365+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . KillTile , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
365366 break ;
366367 case TileModifyType . KillWall :
367- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . PlaceWall , ( float ) x , ( float ) y , ( float ) tile . wall , style ) ;
368+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . PlaceWall , ( float ) x , ( float ) y , ( float ) tile . wall , style ) ;
368369 break ;
369370 case TileModifyType . PlaceWall :
370- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . KillWall , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
371+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . KillWall , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
371372 break ;
372373 case TileModifyType . KillTileNoItem :
373- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . PlaceTile , ( float ) x , ( float ) y , ( float ) tile . type , tile . slope ( ) ) ;
374+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . PlaceTile , ( float ) x , ( float ) y , ( float ) tile . type , tile . slope ( ) ) ;
374375 break ;
375376 case TileModifyType . PlaceWire :
376- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . KillWire , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
377+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . KillWire , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
377378 break ;
378379 case TileModifyType . PlaceWire2 :
379- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . KillWire2 , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
380+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . KillWire2 , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
380381 break ;
381382 case TileModifyType . PlaceWire3 :
382- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . KillWire3 , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
383+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . KillWire3 , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
383384 break ;
384385 case TileModifyType . KillWire :
385- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . PlaceWire , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
386+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . PlaceWire , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
386387 break ;
387388 case TileModifyType . KillWire2 :
388- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . PlaceWire2 , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
389+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . PlaceWire2 , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
389390 break ;
390391 case TileModifyType . KillWire3 :
391- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . PlaceWire3 , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
392+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . PlaceWire3 , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
392393 break ;
393394 case TileModifyType . KillActuator :
394- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . PlaceActuator , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
395+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . PlaceActuator , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
395396 break ;
396397 case TileModifyType . PlaceActuator :
397- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . KillActuator , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
398+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . KillActuator , ( float ) x , ( float ) y , ( float ) placeType , style ) ;
398399 break ;
399400 case TileModifyType . PoundTile :
400- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . PoundTile , ( float ) x , ( float ) y , ( float ) placeType , tile . slope ( ) ) ;
401+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . PoundTile , ( float ) x , ( float ) y , ( float ) placeType , tile . slope ( ) ) ;
401402 break ;
402403 case TileModifyType . SlopeTile :
403- NetMessage . SendData ( 17 , playerNumber , - 1 , "" , ( int ) TileModifyType . SlopeTile , ( float ) x , ( float ) y , ( float ) placeType , tile . slope ( ) ) ;
404+ NetMessage . SendData ( 17 , playerNumber , - 1 , null , ( int ) TileModifyType . SlopeTile , ( float ) x , ( float ) y , ( float ) placeType , tile . slope ( ) ) ;
404405 break ;
405406 }
406407 return true ;
407408 }
408409 break ;
409- case 25 : //revieved a chat message
410+ /* case 25: //received a chat message
410411
411412 binaryReader.ReadByte();
412413 Color color = binaryReader.ReadRGB();
@@ -556,26 +557,26 @@ public static bool CheckIncomingDataForHEROsModMessage(ref byte msgType, ref Bin
556557 }
557558 else
558559 {
559- NetMessage . SendData ( 25 , playerNumber , - 1 , Lang . mp [ 10 ] , 255 , 255f , 240f , 20f , 0 ) ;
560+ NetMessage.SendData(25, playerNumber, -1, Lang.mp[10].ToNetworkText() , 255, 255f, 240f, 20f, 0);
560561 }
561562 }
562563 else
563564 {
564565 return false;
565566 // why are chat messages randomized?
566- /* color = chatColor[chatColorIndex];
567- chatColorIndex++;
568- if (chatColorIndex >= chatColor.Length) chatColorIndex = 0;
569- NetMessage.SendData(25, -1, -1, text, 255, (float)color.R, (float)color.G, (float)color.B, 0);
570- if (Main.dedServ)
571- {
572- Console.WriteLine("<" + Main.player[playerNumber].name + "> " + text);
573- }*/
567+ // color = chatColor[chatColorIndex];
568+ // chatColorIndex++;
569+ // if (chatColorIndex >= chatColor.Length) chatColorIndex = 0;
570+ // NetMessage.SendData(25, -1, -1, text, 255, (float)color.R, (float)color.G, (float)color.B, 0);
571+ // if (Main.dedServ)
572+ // {
573+ // Console.WriteLine("<" + Main.player[playerNumber].name + "> " + text);
574+ //}
574575 }
575576 }
576577 return true;
577578 }
578- break ;
579+ break;*/
579580 //case 27:
580581 // if (ItemBanner.ItemsBanned && !Players[playerNumber].Group.IsAdmin)
581582 // {
@@ -654,7 +655,7 @@ public static bool CheckIncomingDataForHEROsModMessage(ref byte msgType, ref Bin
654655 }
655656 else
656657 {
657- NetMessage . SendData ( 63 , playerNumber , - 1 , "" , x , ( float ) y , ( float ) Main . tile [ x , y ] . color ( ) ) ;
658+ NetMessage . SendData ( 63 , playerNumber , - 1 , null , x , ( float ) y , ( float ) Main . tile [ x , y ] . color ( ) ) ;
658659 SendTextToPlayer ( "You do not have permission to build here" , playerNumber , Color . Red ) ;
659660 return true ;
660661 }
@@ -676,7 +677,7 @@ public static bool CheckIncomingDataForHEROsModMessage(ref byte msgType, ref Bin
676677 }
677678 else
678679 {
679- NetMessage . SendData ( 64 , playerNumber , - 1 , "" , x , ( float ) y , ( float ) Main . tile [ x , y ] . wallColor ( ) ) ;
680+ NetMessage . SendData ( 64 , playerNumber , - 1 , null , x , ( float ) y , ( float ) Main . tile [ x , y ] . wallColor ( ) ) ;
680681 SendTextToPlayer ( "You do not have permission to build here" , playerNumber , Color . Red ) ;
681682 return true ;
682683 }
@@ -752,7 +753,13 @@ public static void HEROsModMessaged(BinaryReader binaryReader, int playerNumber)
752753 private static void PlayerJoined ( int playerNumber )
753754 {
754755 Players [ playerNumber ] = new HEROsModPlayer ( playerNumber ) ;
755- SendTextToPlayer ( HEROsModCheckMessage , playerNumber , Color . Red ) ;
756+ // chat message hack: SendTextToPlayer(HEROsModCheckMessage, playerNumber, Color.Red);
757+
758+ var packet = HEROsMod . instance . GetPacket ( ) ;
759+ packet . Write ( ( byte ) MessageType . LoginMessage ) ;
760+ packet . Write ( ( byte ) LoginService . MessageType . ServerToClientHandshake ) ;
761+ packet . Send ( playerNumber ) ;
762+
756763 GeneralMessages . TellClientsPlayerJoined ( playerNumber ) ;
757764 }
758765
@@ -780,7 +787,7 @@ private static void FreezeNonLoggedInPlayers()
780787 {
781788 //player.GameInstance.AddBuff(47, 7200);
782789 // Console.WriteLine("Freeze " + i);
783- NetMessage . SendData ( 55 , player . Index , - 1 , "" , player . Index , 47 , 120 , 0f , 0 ) ;
790+ NetMessage . SendData ( 55 , player . Index , - 1 , null , player . Index , 47 , 120 , 0f , 0 ) ;
784791 }
785792 }
786793 }
@@ -793,21 +800,23 @@ public static void SendPlayerToPosition(HEROsModPlayer player, Vector2 position)
793800 int prevSpawnY = player . GameInstance . SpawnY ;
794801 player . GameInstance . SpawnX = ( int ) position . X ;
795802 player . GameInstance . SpawnY = ( int ) position . Y ;
796- NetMessage . SendData ( 12 , - 1 , - 1 , "" , player . Index , 0f , 0f , 0f , 0 ) ;
803+ NetMessage . SendData ( 12 , - 1 , - 1 , null , player . Index , 0f , 0f , 0f , 0 ) ;
797804 player . GameInstance . SpawnX = prevSpawnX ;
798805 player . GameInstance . SpawnY = prevSpawnY ;
799806 }
800807
801808 public static void SendTextToPlayer ( string msg , int playerIndex , Color ? color = null )
802809 {
803810 Color c = color . GetValueOrDefault ( Color . White ) ;
804- NetMessage . SendData ( 25 , playerIndex , - 1 , msg , 255 , c . R , c . G , c . B , 0 ) ;
811+ //NetMessage.SendData(25, playerIndex, -1, msg, 255, c.R, c.G, c.B, 0);
812+ NetMessage . SendChatMessageToClient ( NetworkText . FromLiteral ( msg ) , c , playerIndex ) ;
805813 }
806814
807815 public static void SendTextToAllPlayers ( string msg , Color ? color = null )
808816 {
809817 Color c = color . GetValueOrDefault ( Color . White ) ;
810- NetMessage . SendData ( 25 , - 1 , - 1 , msg , 255 , c . R , c . G , c . B , 0 ) ;
818+ //NetMessage.SendData(25, -1, -1, msg, 255, c.R, c.G, c.B, 0);
819+ NetMessage . BroadcastChatMessage ( NetworkText . FromLiteral ( msg ) , c , - 1 ) ;
811820 }
812821
813822 public static void SendDataToServer ( )
@@ -904,7 +913,7 @@ public static void ClearGroundItems()
904913 if ( Main . item [ i ] . active )
905914 {
906915 Main . item [ i ] . SetDefaults ( 0 ) ;
907- NetMessage . SendData ( 21 , - 1 , - 1 , "" , i , 0f , 0f , 0f , 0 ) ;
916+ NetMessage . SendData ( 21 , - 1 , - 1 , null , i , 0f , 0f , 0f , 0 ) ;
908917 }
909918 }
910919 }
@@ -919,7 +928,7 @@ public static void SpawnNPC(int type, Vector2 position)
919928 {
920929 n . position = position ;
921930 npcFound = true ;
922- if ( Main . netMode == 2 ) NetMessage . SendData ( 23 , - 1 , - 1 , "" , i , 0f , 0f , 0f , 0 ) ;
931+ if ( Main . netMode == 2 ) NetMessage . SendData ( 23 , - 1 , - 1 , null , i , 0f , 0f , 0f , 0 ) ;
923932 break ;
924933 }
925934 }
@@ -951,7 +960,7 @@ public static void ResendPlayerTileData(HEROsModPlayer player)
951960 }
952961 }
953962 int num2 = num ;
954- NetMessage . SendData ( 9 , player . Index , - 1 , Lang . inter [ 44 ] , num2 , 0f , 0f , 0f , 0 ) ;
963+ NetMessage . SendData ( 9 , player . Index , - 1 , Lang . inter [ 44 ] . ToNetworkText ( ) , num2 , 0f , 0f , 0f , 0 ) ;
955964 Netplay . Clients [ player . Index ] . StatusText2 = "is receiving tile data" ;
956965 Netplay . Clients [ player . Index ] . StatusMax += num2 ;
957966 for ( int k = sectionX - 1 ; k < sectionX + 2 ; k ++ )
@@ -961,7 +970,7 @@ public static void ResendPlayerTileData(HEROsModPlayer player)
961970 if ( k >= 0 && k < Main . maxSectionsX && l >= 0 && l < Main . maxSectionsY )
962971 {
963972 NetMessage . SendSection ( player . Index , k , l , false ) ;
964- NetMessage . SendData ( 11 , player . Index , - 1 , "" , k , ( float ) l , ( float ) k , ( float ) l , 0 ) ;
973+ NetMessage . SendData ( 11 , player . Index , - 1 , null , k , ( float ) l , ( float ) k , ( float ) l , 0 ) ;
965974 }
966975 }
967976 }
0 commit comments