Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Add command line arguments and config.
Browse files Browse the repository at this point in the history
  • Loading branch information
HybridEidolon committed Jul 9, 2016
1 parent 5c088d7 commit e37378e
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 26 deletions.
63 changes: 63 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ log = "0.3"
env_logger = "0.3"
resolve = "0.1.2"
rand = "0.3"
rustc-serialize = "0.3"
toml = "0.1"
clap = "2"
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
# PSOGC telepipe

[![Travis Build Status](https://travis-ci.org/BygoneWorlds/telepipe.svg?branch=master)](https://travis-ci.org/BygoneWorlds/telepipe)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/BygoneWorlds/telepipe?svg=true&branch=master)](https://ci.appveyor.com/project/Furyhunter/telepipe)
[![Travis Build Status]](https://travis-ci.org/BygoneWorlds/telepipe)
[![AppVeyor Build Status]](https://ci.appveyor.com/project/Furyhunter/telepipe)

A proxy for _Phantasy Star Online_ games for the GameCube.

This program is designed primarily to be used with the [Dolphin emulator] on
systems where [Broadband Adapter] emulation is supported (not macOS), however
it may be used as a normal proxy for real GameCubes and Wiis via PPP emulation
on capable GameCube kernel shims.

## Compiling

Install the latest version of Rust and:
Install the latest stable version of Rust and:

$ cargo build --release

## Using
Omitting the `--release` will build in debug mode; all optimizations will be
omitted, and integer overflow checks will be added.

**TODO**
## Usage

Configuration will be handled by a toml file which specifies the PSO server
to connect to and what interfaces to bind on.
Telepipe 1.0
Eidolon (@HybridEidolon)
A proxy for Phantasy Star Online games for the GameCube.

This program is designed primarily to be used with the [Dolphin emulator] on
systems where [Broadband Adapter] emulation is supported (not macOS), however
it may be used as a normal proxy for real GameCubes and Wiis via PPP emulation
on capable GameCube kernel shims.
USAGE:
telepipe.exe [OPTIONS]

FLAGS:
-h, --help Prints help information
-V, --version Prints version information

OPTIONS:
-c, --config <PATH> Sets the config file. [default: telepipe.toml]

An example config file is located in `telepipe.toml` in the project.

## License

Expand All @@ -30,3 +44,5 @@ Telepipe is licensed under the terms of the [MIT License].
[Dolphin emulator]: http://dolphin-emu.org/
[Broadband Adapter]: https://wiki.dolphin-emu.org/index.php?title=Broadband_Adapter
[MIT License]: http://spdx.org/licenses/MIT.html
[Travis Build Status]: https://travis-ci.org/BygoneWorlds/telepipe.svg?branch=master
[AppVeyor Build Status]: https://ci.appveyor.com/api/projects/status/github/BygoneWorlds/telepipe?svg=true&branch=master
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Clone, RustcDecodable, Debug)]
pub struct Config {
pub bind_addr: String,
pub server_addr: String,
pub listen_ports: Vec<(u16, u16)>,
pub use_dns: bool
}
58 changes: 43 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@ extern crate encoding;
extern crate env_logger;
extern crate resolve;
extern crate rand;
extern crate toml;
extern crate rustc_serialize;
extern crate clap;

pub mod serial;
pub mod msg;
pub mod crypto;
pub mod client;
pub mod session;
pub mod config;

use std::net::Ipv4Addr;
use std::thread;
use std::io::Read;
use std::fs::File;

use clap::{App, Arg};
use resolve::{DnsSocket, MESSAGE_LIMIT, Message as DnsMsg, Resource, RecordType, Class};
use resolve::record;
use resolve::message::Qr;

use session::spawn_new_session;
use config::Config;

fn dns_thread(socket: DnsSocket) {
info!("DNS thread live");
Expand Down Expand Up @@ -50,26 +58,46 @@ fn dns_thread(socket: DnsSocket) {
}

fn main() {
use std::str::FromStr;
use std::net::SocketAddrV4;

env_logger::init().unwrap();

info!("Telepipe");
info!("Waiting for connections...");
let matches = App::new("Telepipe")
.version("1.0")
.author("Eidolon (@HybridEidolon)")
.about("A proxy for Phantasy Star Online games for the GameCube.")
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("PATH")
.help("Sets the config file.")
.default_value("telepipe.toml")
)
.get_matches();

let config = matches.value_of("config").unwrap();

debug!("Config file in use: {}", config);

let sock = DnsSocket::bind(SocketAddrV4::from_str("192.168.150.1:53").unwrap()).unwrap();
thread::spawn(move || {
dns_thread(sock);
});
// Parse the config
let mut contents = String::new();
File::open(config).unwrap().read_to_string(&mut contents).unwrap();
let config: Config = match toml::decode_str::<Config>(&contents) {
Some(c) => c,
None => {
println!("The config file is incorrect. Please correct it.");
return
}
};

spawn_new_session("192.168.150.1:9103", "74.59.188.106:9103", false);
spawn_new_session("192.168.150.1:9003", "74.59.188.106:9003", false);
spawn_new_session("192.168.150.1:9203", "74.59.188.106:9203", false);
spawn_new_session("192.168.150.1:9002", "74.59.188.106:9002", false);
if config.use_dns {
let sock = DnsSocket::bind((config.bind_addr.as_str(), 53)).unwrap();
thread::spawn(move || {
dns_thread(sock);
});
}

spawn_new_session("192.168.150.1:9100", "74.59.188.106:9100", false);
spawn_new_session("192.168.150.1:9001", "74.59.188.106:9001", false);
for (local, server) in config.listen_ports {
spawn_new_session((config.bind_addr.as_str(), local), (config.server_addr.as_str(), server), false);
}

loop {
use std::time::Duration;
Expand Down
32 changes: 32 additions & 0 deletions telepipe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# The local interface IP to bind to. Set to 0.0.0.0 to listen on all interfaces.
#
# Set this to your local computer's LAN IP between your TAP adapter and the host
# if you are using Dolphin without bridging.
bind_addr = "192.168.150.1"

# The address of the PSO server you wish to connect to.
#
# As of this writing (7/9/2016):
# SCHTHACK = 74.59.188.106
# Sylverant = 67.222.144.120
#
# These IPs are seen in the context of the host machine, not the connecting client,
# so you can use 127.0.0.1 if you are running a local server.
server_addr = "74.59.188.106"

# The ports to listen on and map to.
#
# You only need to change this if you are running a PSO server locally that is
# already running on these ports.
#
# Each pair is of the form [local, server]
listen_ports = [
# Episode 3
[9103, 9103], [9003, 9003], [9203, 9203], [9002, 9002],
# Episodes 1&2
[9100, 9100], [9001, 9001]
]

# Whether or not to run a DNS server on port 53. The server will use the same
# bind address as the proxy itself.
use_dns = true

0 comments on commit e37378e

Please sign in to comment.