Added new Project: MudClient
- TODO: Read my ReadME - TODO: Change it into a GUI - Currently it is a console application, Telnet functionality needs to be added as well as \n\r | \r\n correction. Simply create a GUI for it and use the Networking/Client.cs file (see how it is used in the Program.cs).
This commit is contained in:
parent
3110b74b58
commit
7ad027e9d7
5 changed files with 265 additions and 1 deletions
58
MudClient/MudClient.csproj
Normal file
58
MudClient/MudClient.csproj
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
|
<ProductVersion>8.0.30703</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{970B3390-7485-41A5-8465-CFF2580501B6}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>MudClient</RootNamespace>
|
||||||
|
<AssemblyName>MudClient</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
|
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Networking\Client.cs" />
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
96
MudClient/Networking/Client.cs
Normal file
96
MudClient/Networking/Client.cs
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
|
namespace MudClient.Networking
|
||||||
|
{
|
||||||
|
class Client
|
||||||
|
{
|
||||||
|
public Client()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~Client()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public Boolean Initialize(string i, int p)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (i.Length <= 0)
|
||||||
|
return false;
|
||||||
|
ip = i;
|
||||||
|
if (p <= 0)
|
||||||
|
return false;
|
||||||
|
port = p;
|
||||||
|
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public Boolean Connect()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sock.Connect(ip, port);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public Boolean Send(string data,Boolean newLine)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||||
|
if(newLine)
|
||||||
|
data += "\n";
|
||||||
|
sock.Send(encoding.GetBytes(data));
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public Boolean Receive(out string rs,int size)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] data = new byte[size];
|
||||||
|
sock.Receive(data);
|
||||||
|
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
|
||||||
|
rs = enc.GetString(data.ToArray());
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
rs = "";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public Boolean End()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sock.Close();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private string ip;
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
private Socket sock;
|
||||||
|
}
|
||||||
|
}
|
62
MudClient/Program.cs
Normal file
62
MudClient/Program.cs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
// README: This is just a bare down tcp client. It'll work much better with the GUI, also in the receive thread, instead
|
||||||
|
// of receiving one byte at a time your going to want to do what I did with the server and receive the msgs then check them
|
||||||
|
// and act like a telnet client would for example the clear function.
|
||||||
|
// Lastly for some reason I can't relog into my account it could possibly be because with client's Send, it'll add \n, you may
|
||||||
|
// need to add \r\n or \n\r I'm not sure which order.
|
||||||
|
// Any questions feel free to msg me on msn: u8sand@verizon.net or e-mail me u8sand@gmail.com
|
||||||
|
|
||||||
|
namespace MudClient
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static MudClient.Networking.Client client = new MudClient.Networking.Client();
|
||||||
|
static Boolean quit = false;
|
||||||
|
|
||||||
|
static void ReceiveThread()
|
||||||
|
{
|
||||||
|
string output;
|
||||||
|
while (!quit)
|
||||||
|
{
|
||||||
|
if (!client.Receive(out output, 1))
|
||||||
|
quit = true;
|
||||||
|
else
|
||||||
|
Console.Write(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
|
||||||
|
string input,ip;
|
||||||
|
int port;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
Console.Write("IP: ");
|
||||||
|
ip = Console.ReadLine();
|
||||||
|
Console.Write("Port: ");
|
||||||
|
input = Console.ReadLine();
|
||||||
|
int.TryParse(input, out port);
|
||||||
|
} while (!client.Initialize(ip, port));
|
||||||
|
if (!client.Connect() || !client.Send("666", false)) // test send + client data
|
||||||
|
Console.WriteLine("Failed to connect to server.");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Thread r = new Thread(ReceiveThread);
|
||||||
|
r.Start();
|
||||||
|
while (!quit)
|
||||||
|
{
|
||||||
|
input = Console.ReadLine();
|
||||||
|
if (!client.Send(input, true))
|
||||||
|
quit = true;
|
||||||
|
}
|
||||||
|
r.Abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
MudClient/Properties/AssemblyInfo.cs
Normal file
36
MudClient/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("MudClient")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Hewlett-Packard")]
|
||||||
|
[assembly: AssemblyProduct("MudClient")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Hewlett-Packard 2010")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("2e8a5bd5-9d60-4af4-8538-04540ca80f02")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// 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.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -1,12 +1,14 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||||
# Visual C# Express 2010
|
# Visual Studio 2010
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudEngine", "MudEngine\MudEngine.csproj", "{498943A8-DF5A-4DB0-B506-0BFF44788657}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudEngine", "MudEngine\MudEngine.csproj", "{498943A8-DF5A-4DB0-B506-0BFF44788657}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MUDCompiler", "MUDCompiler\MUDCompiler.csproj", "{98E974DA-C650-4B88-B2F8-57AC7AE6C34F}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MUDCompiler", "MUDCompiler\MUDCompiler.csproj", "{98E974DA-C650-4B88-B2F8-57AC7AE6C34F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudGame", "MudGame\MudGame.csproj", "{0C47648F-8751-4A71-98ED-A3D0845627E2}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudGame", "MudGame\MudGame.csproj", "{0C47648F-8751-4A71-98ED-A3D0845627E2}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MudClient", "MudClient\MudClient.csproj", "{970B3390-7485-41A5-8465-CFF2580501B6}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -47,6 +49,16 @@ Global
|
||||||
{0C47648F-8751-4A71-98ED-A3D0845627E2}.Release|Mixed Platforms.Build.0 = Release|x86
|
{0C47648F-8751-4A71-98ED-A3D0845627E2}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||||
{0C47648F-8751-4A71-98ED-A3D0845627E2}.Release|x86.ActiveCfg = Release|x86
|
{0C47648F-8751-4A71-98ED-A3D0845627E2}.Release|x86.ActiveCfg = Release|x86
|
||||||
{0C47648F-8751-4A71-98ED-A3D0845627E2}.Release|x86.Build.0 = Release|x86
|
{0C47648F-8751-4A71-98ED-A3D0845627E2}.Release|x86.Build.0 = Release|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Release|Any CPU.ActiveCfg = Release|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{970B3390-7485-41A5-8465-CFF2580501B6}.Release|x86.Build.0 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue