Skip to content

Commit

Permalink
First release.
Browse files Browse the repository at this point in the history
Configurable image directory, show IP on server launch, vobf.
  • Loading branch information
thquinn committed Feb 20, 2015
1 parent 805839c commit c580a40
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 60 deletions.
16 changes: 2 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache
*.cache
obj/x86/Debug/IsochronDrafter.CardWindow.resources
*.resources
obj/x86/Debug/IsochronDrafter.csproj.FileListAbsolute.txt
obj/x86/Debug/IsochronDrafter.exe
obj/x86/Debug/IsochronDrafter.pdb
bin/Debug/tcpServer.pdb
bin/Debug/tcpServer.dll
bin/Debug/IsochronDrafter.vshost.exe.manifest
bin/Debug/IsochronDrafter.vshost.exe
bin/Debug/IsochronDrafter - Copy.exe
bin/Debug/IsochronDrafter.exe
bin/Debug/IsochronDrafter.pdb
bin/*
obj/*
31 changes: 15 additions & 16 deletions ConnectWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ConnectWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public ConnectWindow()
{
InitializeComponent();
MaximizeBox = false;
#if DEBUG
textBox1.Text = "isochron.us.to";
#endif
}

// Connect.
Expand Down
7 changes: 7 additions & 0 deletions DraftClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private void HandleMessage(string msg)
else if (parts[1] == "PICK")
{
draftWindow.ClearDraftPicker();
draftWindow.EnableDraftPicker();
}
}
else if (parts[0] == "ERROR")
Expand All @@ -87,6 +88,11 @@ private void HandleMessage(string msg)
draftWindow.PrintLine("Unknown error from server: " + parts[1]);
client.Disconnect();
}
else if (parts[0] == "IMAGE_DIR")
{
Util.imageDirectory = parts[1];
draftWindow.PrintLine("Set image directory.");
}
else if (parts[0] == "USER_CONNECTED")
{
if (parts[1] != alias)
Expand All @@ -106,6 +112,7 @@ private void HandleMessage(string msg)
else if (parts[0] == "BOOSTER")
{
draftWindow.PopulateDraftPicker(msg);
draftWindow.EnableDraftPicker();
}
else if (parts[0] == "CARD_POOL")
{
Expand Down
5 changes: 5 additions & 0 deletions DraftPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public void Populate(List<String> cardNames)
DraftWindow.LoadImage(cardName);
Invalidate();
}
public void Clear()
{
cardNames = new List<string>();
Invalidate();
}

protected override void OnPaint(PaintEventArgs e)
{
Expand Down
17 changes: 15 additions & 2 deletions DraftServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,25 @@ public DraftServer(ServerWindow serverWindow, string setFilename)
ParseText(File.ReadAllText(setFilename));
serverWindow.PrintLine("Loaded set: " + setName + ".");

// Get public IP address of server.
string url = "http://checkip.dyndns.org";
System.Net.WebRequest req = System.Net.WebRequest.Create(url);
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
string response = sr.ReadToEnd().Trim();
string[] a = response.Split(':');
string a2 = a[1].Substring(1);
string[] a3 = a2.Split('<');
string ip = a3[0];


server = new TcpServer();
server.Port = 10024;
server.OnConnect += OnConnect;
server.OnDisconnect += OnDisconnect;
server.OnDataAvailable += OnDataAvailable;
server.Open();
serverWindow.PrintLine("Launched server on port " + server.Port + ". Accepting connections.");
serverWindow.PrintLine("Launched server at " + ip + " on port " + server.Port + ". Accepting connections.");
}

private void OnConnect(TcpServerConnection connection)
Expand Down Expand Up @@ -135,6 +147,7 @@ private void HandleMessage(TcpServerConnection connection, string msg)
serverWindow.PrintLine("<" + GetAlias(connection) + "> has new alias " + parts[1] + ".");
aliases.TryAdd(connection, parts[1]);
TrySendMessage(connection, "OK|ALIAS");
TrySendMessage(connection, "IMAGE_DIR|" + Util.imageDirectory);
TrySendMessage("USER_CONNECTED|" + parts[1]);
if (draftStarted)
{
Expand Down Expand Up @@ -167,7 +180,7 @@ private void HandleMessage(TcpServerConnection connection, string msg)
booster.RemoveAt(pickIndex);
draftState.boosters.Remove(booster);
TrySendMessage(connection, "OK|PICK");
serverWindow.PrintLine("<" + draftState.alias + "> picked " + pick + ".");
serverWindow.PrintLine("<" + draftState.alias + "> made a pick.");

// Pass the pack to the next player, if not empty.
if (booster.Count > 0)
Expand Down
14 changes: 12 additions & 2 deletions DraftWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class DraftWindow : Form
private static Dictionary<string, Image> cardImages = new Dictionary<string, Image>();
public CardWindow cardWindow;
public DraftClient draftClient;
public bool canPick = true;

public DraftWindow()
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public static void LoadImage(string cardName)
{
if (cardImages.ContainsKey(cardName))
return;
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("https://dl.dropboxusercontent.com/u/1377551/IsochronDrafter/" + cardName.Replace(",", "").Replace("’", "") + ".full.jpg");
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(Util.imageDirectory + cardName.Replace(",", "").Replace("’", "") + ".full.jpg");
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();
cardImages.Add(cardName, Image.FromStream(stream));
Expand All @@ -88,7 +89,11 @@ public void PopulateDraftPicker(string message)
}
public void ClearDraftPicker()
{
draftPicker.Populate(new List<string>());
draftPicker.Clear();
}
public void EnableDraftPicker()
{
canPick = true;
}
public void AddCardToPool(string cardName)
{
Expand All @@ -107,10 +112,15 @@ public void ClearCardPool()

private void draftPicker1_DoubleClick(object sender, EventArgs e)
{
if (!canPick)
return;
MouseEventArgs me = e as MouseEventArgs;
int index = draftPicker.GetIndexFromCoor(me.X, me.Y);
if (index != -1)
{
canPick = false;
draftClient.Pick(index, draftPicker.cardNames[index]);
}
}

// Menu items.
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@ A hacked-together way to draft custom Magic: the Gathering sets online.
## Features
* Draft custom Magic sets online with your friends!
* Graphical deck builder allows you to build your deck as you draft!
* That's it.
* That's it. [Screenshot.](http://i.imgur.com/ssYb7TB.jpg)

## Requirements
Windows and .NET 4.0, until someone wants to do a Mono port.

## What's Broken?
Well, a lot of stuff. For starters:
* Slow image downloading
* Scrollbars sometimes flicker rapidly when they appear/disappear
* Very little error handling when parsing set files, loading images, etc.
* Little to no error handling when parsing set files, loading images, etc.

## Coming Soon
* A more configurable server
## Coming Eventually
* Graphical bug fixes
* More error handling
* Miscellaneous beautification
* More info about table order, who has how many packs during drafts
* Resizable windows
* Better image downloading

## How to Use
NOTE: This process will get much easier shortly.
* Export your set from Magic Set Editor using the script in the scripts/ directory.
* Export card images from your set -- filename must be "<cardname>.full.jpg".
* Upload the card images from your set somewhere.
* Fix the base image directory in LoadImage(...) in DraftWindow.cs. Recompile.
* In Isochron Drafter, start a server and select the exported set.
* In Isochron Drafter, start a server, browse to the set file, enter the image directory.
* Have everyone connect to the IP you're hosting the server on.
* Start the draft on the server.
* Enjoy.

## Notes
* Isochron Drafter was written by Tom Quinn, and is available under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-nc-sa/4.0/).
* It uses Craig Baird's [C# TCP Server](http://www.codeproject.com/Articles/488668/Csharp-TCP-Server) and skatamatic's [Event-Driven TCP Client](https://www.daniweb.com/software-development/csharp/code/422291/user-friendly-asynchronous-event-driven-tcp-client).
* It uses Craig Baird's [C# TCP Server](http://www.codeproject.com/Articles/488668/Csharp-TCP-Server) and skatamatic's [Event-Driven TCP Client](https://www.daniweb.com/software-development/csharp/code/422291/user-friendly-asynchronous-event-driven-tcp-client), each with some minor changes.
* It is really hacked together, and not at all representative of my overall coding style or quality. Don't judge... ;_;
* Find my other stuff at my [portfolio site](http://cargocollective.com/tomquinn), and let me know what you think!
73 changes: 65 additions & 8 deletions ServerWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c580a40

Please sign in to comment.