Advertisement
Guest User

SDK

a guest
Dec 9th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.61 KB | None | 0 0
  1. extern crate libc;
  2.  
  3. use libc::{c_char, c_void};
  4. use std::ffi::CString;
  5.  
  6. #[link(name = "vpsdk")]
  7. extern "system" {
  8.     fn vp_init(version: i64) -> i64;
  9.     fn vp_create() -> &mut c_void;
  10.     fn vp_connect_universe(instance: &mut c_void, host: *const c_char, port: u32) -> i64;
  11.     fn vp_login(instance: &mut c_void, username: *const c_char, password: *const c_char, botname: *const c_char) -> i64;
  12.     fn vp_enter(instance: &mut c_void, worldname: *const c_char) -> i64;
  13.     fn vp_state_change(instance: &mut c_void) -> i64;
  14. }
  15.  
  16. fn main() {
  17.     let x = unsafe { vp_init(3) };
  18.     if x != 0 {
  19.         panic!("Could not initialize vpsdk!");
  20.     }
  21.  
  22.     let mut sdk = unsafe { vp_create() };
  23.  
  24.     let err = unsafe {
  25.         let host = CString::new("universe.virtualparadise.org").unwrap();
  26.         vp_connect_universe(&mut sdk, host.as_ptr(), 57000)
  27.     };
  28.     if err != 0 {
  29.         panic!("Could not connect to universe!");
  30.     }
  31.  
  32.     let err = unsafe {
  33.         let user = CString::new("Ray").unwrap();
  34.         let pass = CString::new("iswork").unwrap();
  35.         let name = CString::new("Rust API Test").unwrap();
  36.         vp_login(&mut sdk, user.as_ptr(), pass.as_ptr(), name.as_ptr())
  37.     };
  38.     if err != 0 {
  39.         panic!("Could not login to universe!");
  40.     }
  41.  
  42.     let err = unsafe {
  43.         let world = CString::new("Blizzard").unwrap();
  44.         vp_enter(&mut sdk, world.as_ptr())
  45.     };
  46.     if err != 0 {
  47.         panic!("Could not enter world!");
  48.     }
  49.  
  50.     let err = unsafe {
  51.         vp_state_change(&mut sdk)
  52.     };
  53.     if err != 0 {
  54.         panic!("Could not change state!");
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement