diff --git a/Terrafirma/ConnectToServer.xaml b/Terrafirma/ConnectToServer.xaml
new file mode 100644
index 0000000..087ceaa
--- /dev/null
+++ b/Terrafirma/ConnectToServer.xaml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Terrafirma/ConnectToServer.xaml.cs b/Terrafirma/ConnectToServer.xaml.cs
new file mode 100644
index 0000000..d78f24c
--- /dev/null
+++ b/Terrafirma/ConnectToServer.xaml.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace Terrafirma
+{
+ ///
+ /// Interaction logic for ConnectToServer.xaml
+ ///
+ public partial class ConnectToServer : Window
+ {
+ public ConnectToServer()
+ {
+ InitializeComponent();
+ }
+ public string ServerIP
+ {
+ get { return serverip.Text; }
+ }
+ public int ServerPort
+ {
+ get { return Convert.ToInt16(serverport.Text); }
+ }
+
+ private void button1_Click(object sender, RoutedEventArgs e) //connect
+ {
+ DialogResult = true;
+ this.Close();
+ }
+
+ private void button2_Click(object sender, RoutedEventArgs e) //cancel
+ {
+ DialogResult = false;
+ this.Close();
+ }
+ }
+}
diff --git a/Terrafirma/MainWindow.xaml b/Terrafirma/MainWindow.xaml
index e000ed0..21f895a 100644
--- a/Terrafirma/MainWindow.xaml
+++ b/Terrafirma/MainWindow.xaml
@@ -13,6 +13,8 @@
+
@@ -86,5 +88,8 @@
+
diff --git a/Terrafirma/MainWindow.xaml.cs b/Terrafirma/MainWindow.xaml.cs
index e80d037..eb7541b 100644
--- a/Terrafirma/MainWindow.xaml.cs
+++ b/Terrafirma/MainWindow.xaml.cs
@@ -44,6 +44,7 @@
using System.Windows.Interop;
using System.Collections;
using System.Threading;
+using System.Net.Sockets;
namespace Terrafirma
{
@@ -251,6 +252,11 @@ public partial class MainWindow : Window
UInt32 skyColor, earthColor, rockColor, hellColor, lavaColor, waterColor;
bool isHilight = false;
+ Socket socket;
+ byte[] readBuffer,writeBuffer;
+ int pendingSize;
+ byte[] messages;
+
public MainWindow()
{
InitializeComponent();
@@ -1100,6 +1106,168 @@ private void Refresh_Executed(object sender, ExecutedRoutedEventArgs e)
load.Close();
}
+ private void ConnectToServer_Executed(object sender, ExecutedRoutedEventArgs e)
+ {
+ //we should disconnect if connected.
+
+ ConnectToServer c = new ConnectToServer();
+ if (c.ShowDialog() == true)
+ {
+ string serverip = c.ServerIP;
+ int port = c.ServerPort;
+ if (serverip == "")
+ {
+ MessageBox.Show("Invalid server address");
+ return;
+ }
+ if (port == 0)
+ {
+ MessageBox.Show("Invalid port");
+ return;
+ }
+
+ socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ System.Net.IPAddress ip;
+ try
+ {
+ ip = System.Net.IPAddress.Parse(serverip);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Invalid server IP");
+ return;
+ }
+ System.Net.IPEndPoint remoteEP = new System.Net.IPEndPoint(ip, port);
+ socket.BeginConnect(remoteEP, new AsyncCallback(connected), null);
+ }
+ }
+ private void connected(IAsyncResult ar)
+ {
+ try
+ {
+ socket.EndConnect(ar);
+ //we connected, huzzah!
+ readBuffer = new byte[1024];
+ writeBuffer = new byte[1024];
+ messages = new byte[8192];
+ pendingSize = 0;
+ SendMessage(1); //greetings server!
+ socket.BeginReceive(readBuffer, 0, readBuffer.Length, SocketFlags.None,
+ new AsyncCallback(ReceivedData), null);
+ }
+ catch (Exception e)
+ {
+ socket.Close();
+ MessageBox.Show(e.Message);
+ }
+ }
+
+ private void ReceivedData(IAsyncResult ar)
+ {
+ try
+ {
+ int bytesRead = socket.EndReceive(ar);
+ if (bytesRead > 0)
+ {
+ Buffer.BlockCopy(readBuffer, 0, messages, pendingSize, bytesRead);
+ pendingSize += bytesRead;
+ messagePump();
+ socket.BeginReceive(readBuffer, 0, readBuffer.Length, SocketFlags.None,
+ new AsyncCallback(ReceivedData), null); //restart receive
+ }
+ else
+ {
+ // socket was closed?
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message);
+ }
+ }
+
+ private void messagePump()
+ {
+ if (pendingSize < 5) //haven't received enough data for even a message header
+ return;
+ int msgLen = BitConverter.ToInt32(messages, 0);
+ int ofs = 0;
+ while (ofs + 4 + msgLen <= pendingSize)
+ {
+ HandleMessage(ofs + 4, msgLen);
+ ofs += msgLen + 4;
+ if (ofs + 4 <= pendingSize)
+ msgLen = BitConverter.ToInt32(messages, ofs);
+ else
+ break;
+ }
+ if (ofs == pendingSize)
+ pendingSize = 0;
+ else if (ofs > 0)
+ {
+ Buffer.BlockCopy(messages, ofs, messages, 0, pendingSize - ofs);
+ pendingSize -= ofs;
+ }
+ }
+
+ private void HandleMessage(int start, int len)
+ {
+ int messageid = messages[start];
+ start++;
+ len--;
+ switch (messageid)
+ {
+ case 37: //request password.
+ ServerPassword s = new ServerPassword();
+ if (s.ShowDialog() == true)
+ SendMessage(38, s.Password);
+ else
+ socket.Close(); //cancelled? Then we're leaving the server.
+ break;
+ default:
+ MessageBox.Show(String.Format("Got response {0}", messageid));
+ break;
+ }
+ }
+
+ private void SendMessage(int messageid,string text=null)
+ {
+ int payload = 5;
+ int payloadLen = 0;
+ switch (messageid)
+ {
+ case 1: //send greeting
+ byte[] greeting = Encoding.ASCII.GetBytes("Terraria" + MapVersion);
+ payloadLen = greeting.Length;
+ Buffer.BlockCopy(greeting, 0, writeBuffer, payload, payloadLen);
+ break;
+ case 38: //send password
+ byte[] password = Encoding.ASCII.GetBytes(text);
+ payloadLen = password.Length;
+ Buffer.BlockCopy(password, 0, writeBuffer, payload, payloadLen);
+ break;
+ default:
+ throw new Exception(String.Format("Unknown messageid: {0}", messageid));
+ }
+
+ byte[] msgLen=BitConverter.GetBytes(payloadLen+1);
+ Buffer.BlockCopy(msgLen, 0, writeBuffer, 0, 4);
+ writeBuffer[4]=(byte)messageid;
+ socket.BeginSend(writeBuffer, 0, payloadLen + 5, SocketFlags.None,
+ new AsyncCallback(SentMessage), null);
+ }
+ private void SentMessage(IAsyncResult ar)
+ {
+ try
+ {
+ socket.EndSend(ar);
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message);
+ }
+ }
+
private void Hilight_Executed(object sender, ExecutedRoutedEventArgs e)
{
ArrayList items = tileInfos.Items();
diff --git a/Terrafirma/MapCommands.cs b/Terrafirma/MapCommands.cs
index 74b0a15..e686777 100644
--- a/Terrafirma/MapCommands.cs
+++ b/Terrafirma/MapCommands.cs
@@ -60,5 +60,7 @@ static class MapCommands
"Show NPC Houses", "Houses", typeof(MapCommands));
public static readonly RoutedUICommand Wires = new RoutedUICommand(
"Show Wires", "Wires", typeof(MapCommands));
+ public static readonly RoutedUICommand ConnectToServer = new RoutedUICommand(
+ "Connect to Server...", "ConnectToServer", typeof(MapCommands));
}
}
diff --git a/Terrafirma/Properties/AssemblyInfo.cs b/Terrafirma/Properties/AssemblyInfo.cs
index 99279af..b65bf77 100644
--- a/Terrafirma/Properties/AssemblyInfo.cs
+++ b/Terrafirma/Properties/AssemblyInfo.cs
@@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.9.2.0")]
-[assembly: AssemblyFileVersion("1.9.2.0")]
+[assembly: AssemblyVersion("1.9.3.0")]
+[assembly: AssemblyFileVersion("1.9.3.0")]
diff --git a/Terrafirma/Render.cs b/Terrafirma/Render.cs
index 4ba393f..c093bc3 100644
--- a/Terrafirma/Render.cs
+++ b/Terrafirma/Render.cs
@@ -364,6 +364,7 @@ private struct Delayed
if (tiles[delay.offset].type == 128) //armor
{
+ int dy=8;
int au = tiles[delay.offset].u % 100;
int armor = tiles[delay.offset].u / 100;
switch (tiles[delay.offset].v)
@@ -372,24 +373,27 @@ private struct Delayed
tex = Textures.GetArmorHead(armor);
texw = 40;
texh = 36;
+ dy = 12;
break;
case 18: //body
tex = Textures.GetArmorBody(armor);
texw = 40;
texh = 54;
+ dy = 28;
break;
default: //legs
tex = Textures.GetArmorLegs(armor);
texw = 40;
texh = 54;
+ dy = 44;
break;
}
if (au >= 36) //reverse
- drawTextureFlip(tex, texw, texh, tiles[delay.offset].v * tex.width * 4 + au * 4,
- pixels, delay.px, delay.py - 8, width, height, scale / 16.0, lightR, lightG, lightB);
+ drawTexture(tex, texw, texh, 0,
+ pixels, delay.px-4, delay.py - dy, width, height, scale / 16.0, lightR, lightG, lightB);
else
- drawTexture(tex, texw, texh, tiles[delay.offset].v * tex.width * 4 + au * 4,
- pixels, delay.px, delay.py - 8, width, height, scale / 16.0, lightR, lightG, lightB);
+ drawTextureFlip(tex, texw, texh, 0,
+ pixels, delay.px-4, delay.py - dy, width, height, scale / 16.0, lightR, lightG, lightB);
}
else if (tiles[delay.offset].type == 5) //tree leaves
{
diff --git a/Terrafirma/ServerPassword.xaml b/Terrafirma/ServerPassword.xaml
new file mode 100644
index 0000000..b329b3d
--- /dev/null
+++ b/Terrafirma/ServerPassword.xaml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
diff --git a/Terrafirma/ServerPassword.xaml.cs b/Terrafirma/ServerPassword.xaml.cs
new file mode 100644
index 0000000..d9b4e5d
--- /dev/null
+++ b/Terrafirma/ServerPassword.xaml.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace Terrafirma
+{
+ ///
+ /// Interaction logic for ServerPassword.xaml
+ ///
+ public partial class ServerPassword : Window
+ {
+ public ServerPassword()
+ {
+ InitializeComponent();
+ }
+ public string Password
+ {
+ get { return password.Password; }
+ }
+
+ private void button1_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = true;
+ }
+ }
+}
diff --git a/Terrafirma/Terrafirma.csproj b/Terrafirma/Terrafirma.csproj
index 530cd97..b8a4cdd 100644
--- a/Terrafirma/Terrafirma.csproj
+++ b/Terrafirma/Terrafirma.csproj
@@ -60,6 +60,9 @@
MSBuild:Compile
Designer
+
+ ConnectToServer.xaml
+
SaveOptions.xaml
@@ -67,6 +70,9 @@
Saving.xaml
+
+ ServerPassword.xaml
+
SignPopup.xaml
@@ -75,6 +81,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -112,6 +122,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/terrafirma.wxs b/terrafirma.wxs
index e76f08a..48eadae 100644
--- a/terrafirma.wxs
+++ b/terrafirma.wxs
@@ -1,6 +1,6 @@
-
+