Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate libc;
- use libc::{c_char, c_void};
- use std::ffi::CString;
- #[link(name = "vpsdk")]
- extern "system" {
- fn vp_init(version: i64) -> i64;
- fn vp_create() -> &mut c_void;
- fn vp_connect_universe(instance: &mut c_void, host: *const c_char, port: u32) -> i64;
- fn vp_login(instance: &mut c_void, username: *const c_char, password: *const c_char, botname: *const c_char) -> i64;
- fn vp_enter(instance: &mut c_void, worldname: *const c_char) -> i64;
- fn vp_state_change(instance: &mut c_void) -> i64;
- }
- fn main() {
- let x = unsafe { vp_init(3) };
- if x != 0 {
- panic!("Could not initialize vpsdk!");
- }
- let mut sdk = unsafe { vp_create() };
- let err = unsafe {
- let host = CString::new("universe.virtualparadise.org").unwrap();
- vp_connect_universe(&mut sdk, host.as_ptr(), 57000)
- };
- if err != 0 {
- panic!("Could not connect to universe!");
- }
- let err = unsafe {
- let user = CString::new("Ray").unwrap();
- let pass = CString::new("iswork").unwrap();
- let name = CString::new("Rust API Test").unwrap();
- vp_login(&mut sdk, user.as_ptr(), pass.as_ptr(), name.as_ptr())
- };
- if err != 0 {
- panic!("Could not login to universe!");
- }
- let err = unsafe {
- let world = CString::new("Blizzard").unwrap();
- vp_enter(&mut sdk, world.as_ptr())
- };
- if err != 0 {
- panic!("Could not enter world!");
- }
- let err = unsafe {
- vp_state_change(&mut sdk)
- };
- if err != 0 {
- panic!("Could not change state!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement