Example #1
0
func (this *PingController) Tcp(data map[string]interface{}, cli *core.Client) {
	result, _ := com.JsonEncode(map[string]interface{}{
		"result": true,
		"msg":    "pong",
	})
	cli.Write(result)
}
Example #2
0
func (this *TaskAddController) Tcp(data map[string]interface{}, cli *core.Client) {
	judge.AddTask(data)

	result, _ := com.JsonEncode(map[string]interface{}{
		"result": true, //bool, login result
		"msg":    "task added",
	})
	cli.Write(result)
}
Example #3
0
func (this *GatherController) Tcp(data map[string]interface{}, cli *core.Client) {
	info := &judge.Info{}
	sid := data["sid"].(string)
	id := data["id"].(float64)
	information := info.Gather(sid, int(id), core.C.Get(runtime.GOOS, "buildpath"))

	result, _ := com.JsonEncode(map[string]interface{}{
		"info": information,

		"time": 123456789,
		"sid":  sid,
		"id":   id,
	})
	cli.Write(result)
}
Example #4
0
func (this *LoginController) Tcp(data map[string]interface{}, cli *core.Client) {
	sess := &models.SessionTab{}
	password := core.C.Get("", "password")

	passwordRecv, ok := data["password"].(string)
	if !ok {
		result, _ := com.JsonEncode(map[string]interface{}{
			"result": false, //bool, login result
			"msg":    "invalid password, password must be string.",
		})
		cli.Write(result)
		return
	}
	if password != passwordRecv {
		result, _ := com.JsonEncode(map[string]interface{}{
			"result": false, //bool, login result
			"msg":    "wrong password.",
		})
		cli.Write(result)
		cli.Close()
		return
	}

	sid, ok := data["sid"]
	if ok {
		sidString, ok := sid.(string)
		if !ok {
			result, _ := com.JsonEncode(map[string]interface{}{
				"result": false, //bool, login result
				"msg":    "invalid sid, sid must be a string.",
			})
			cli.Write(result)
			return
		}

		s, err := sess.GetSession(sidString)
		if err == nil && s.Session == sidString {
			// login success
			cli.Login(true)
			result, _ := com.JsonEncode(map[string]interface{}{
				"result": true, //bool, login result
				"sid":    sid,
				"os":     runtime.GOOS + " " + runtime.GOARCH,
				"language": map[string]interface{}{ //language:compiler
					"C":    "gcc",
					"C++":  "g++",
					"Java": "javac version 1.7",
				},
				"time": 123456789, //server time stamp
			})
			cli.Write(result)
		} else {
			result, _ := com.JsonEncode(map[string]interface{}{
				"result": false, //bool, login result
				"msg":    "invalid sid, please login without sid.",
			})
			cli.Write(result)
		}
	} else {
		sid, err := sess.CreateSession()
		if err != nil {
			result, _ := com.JsonEncode(map[string]interface{}{
				"result": false, //bool, login result
				"msg":    "create session failed. please contact the admin.",
			})
			cli.Write(result)
		} else {
			cli.Login(true)
			result, _ := com.JsonEncode(map[string]interface{}{
				"result": true, //bool, login result
				"sid":    sid,
				"os":     runtime.GOOS + " " + runtime.GOARCH,
				"language": map[string]interface{}{ //language:compiler
					"C":    "gcc",
					"C++":  "g++",
					"Java": "javac version 1.7",
				},
				"time": 123456789, //server time stamp
			})
			cli.Write(result)
		}
	}

}